home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / date.lha / Date / C / src / Date.c < prev    next >
Encoding:
Text File  |  1995-02-04  |  152.1 KB  |  6,018 lines

  1. /* Date / Copyright 1994-95 by Kai Hofmann
  2. ******* Date/--history-- ****************************************************
  3. *
  4. *   NAME
  5. *    history -- This is the development history of the Date module
  6. *
  7. *   VERSION
  8. *    $VER: Date 33.100 (04.02.1995)
  9. *
  10. *   HISTORY
  11. *    16.01.1994 -    Procedures: JulianLeapYear(), GregorianLeapYear() &
  12. *            HeisLeapYear() initiated.
  13. *    22.01.1994 -    Procedures: JulianMonthDays(), GregorianMonthDays(),
  14. *            HeisMonthDays(), JulianYearDays(),
  15. *            GregorianYearDays(), HeisYearDays(), JulianDayDiff(),
  16. *            GregorianDayDiff(), HeisDayDiff(),
  17. *            JulianDaySmaller(), GregorianDaySmaller(),
  18. *            HeisDaySmaller(), JulianWeekday(),
  19. *            GregorianWeekday(), HeisWeekday(),
  20. *            JulianDaysBeforeWeekday(),
  21. *            GregorianDaysBeforeWeekday(),
  22. *            HeisDaysBeforeWeekday(), JulianDaysAfterWeekday(),
  23. *            GregorianDaysAfterWeekday(), HeisDaysAfterWeekday(),
  24. *            JulianDiffDate(), FreeDate() initiated.
  25. *            Types: Weekdays, Date, DatePtr initiated.
  26. *            Vars of Gregorian reform initiated
  27. *            (for changing to different countries)
  28. *    23.01.1994 -    Procedures: JulianDiffDate() finished,
  29. *            GregorianDiffDate(), HeisDiffDate(),
  30. *            JYearToScaliger(), GYearToScaliger(),
  31. *            HYearToScaliger(), ScaligerYearToJ(),
  32. *            ScaligerYearToG(), ScaligerYearToH(), JSYearToJD(),
  33. *            GSYearToJD(), HSYearToJD(), JDtoMJD(), MJDtoJD(),
  34. *            JulianToJD(), GregorianToJD(), HeisToJD(),
  35. *            TimeToJD(), JDToTime(), FreeTime() initiated.
  36. *            Types: Time, TimePtr initiated.
  37. *    28.01.1994 -    Procedures: GregorianMoonAge(), MoonMonthAge(),
  38. *            GregorianEaster() initiated.
  39. *    30.01.1994 -    Procedures: JulianDiffDate(), GregorianDiffDate(),
  40. *            HeisDiffDate(), JDToTime(), GregorianEaster() edited
  41. *            (changing return value from ptr to VAL variables).
  42. *            Procedures: FreeDate(), FreeTime() deleted.
  43. *            Types: Date, DatePtr, Time, TimePtr deleted (not
  44. *            longer needed, because of the procedure changes).
  45. *            Procedures: GregorianMoonAge(), GregorianEaster()
  46. *            changed    year parameter from CARDINAL to INTEGER
  47. *            (this is more consistent to the rest of the library).
  48. *            Bugs removed: GregorianWeekday(), HeisWeekday()
  49. *            (before removing, the weekday for leapyears was
  50. *            wrong)
  51. *            Procedure: GregorianEaster() finished.
  52. *    30.01.1994 -    Ported to Oberon-2
  53. *    31.01.1994 -    Compiled with Oberon-2 V3.11
  54. *    12.02.1994 -    Procedures: TimeZoneFactor(), LMT(), TimeToSec(),
  55. *            SecToTime() initiated.
  56. *            Version-String installed :)
  57. *    12.02.1994 -    Starting translation to SAS C 6.51
  58. *            Date.h translated
  59. *    13.02.1994 -    Continuation of C translation
  60. *    17.02.1994 -    New Oberon-2 Port, because yesterday Daniel Amor
  61. *            gives me a small hint about the SHORT command
  62. *            (I did not know about this!)
  63. *    17.02.1994 -    Small bug in Autodocs removed
  64. *            making this text as Date/--history-- autodoc
  65. *    17.02.1994 -    Continuation of C translation
  66. *    18.02.1994 -    Finished with C translation
  67. *    19.02.1994 -    C bugs removed (thanks to SAS for helping a C Lamer
  68. *            like me!), some optimizations done too.
  69. *    19.02.1994 -    Oberon-2 version compiled with V40.17 includes
  70. *    21.02.1994 -    Starting to write Modula-II testmodule
  71. *            Vars for the begining of Heis calculation initiated.
  72. *            Fixed small bugs in GregorianWeekday(),
  73. *            HeisWeekday(), TimeToSec(), SecToTime()
  74. *            Return-value of LMT() changed to LONGINT!
  75. *            Converting testmodule to Oberon-2
  76. *    22.02.1994 -    Converting testmodule to C
  77. *    23.02.1994 -    I noticed, that I forgot the 3 functions
  78. *            JulianWeek(), GregorianWeek(), HeisWeek()
  79. *    24.02.1994 -    Initiated the 3 forgotten functions
  80. *    26.02.1994 -    Initiating new GregorianEaster() with
  81. *            Gauß-algorithms    but ONLY for 1900-2099!
  82. *    27.02.1994 -    Bug fixed in JulianWeekday()
  83. *            Bugs fixed in JulianDayDiff(), GregorianDayDiff(),
  84. *            HeisDayDiff()
  85. *            JulianDayGreater(), GregorianDayGreater(),
  86. *            HeisDayGreater() Initiated.
  87. *    02.03.1994 -    Small bug fixed in HeisDayDiff()
  88. *            Bugs from 27.02. fixed in Modula-II and Oberon-2
  89. *            versions
  90. *            I found the way to extend GregorianEaster() !
  91. *            Little bug fixed in JulianWeek(), GregorianWeek(),
  92. *            HeisWeek() (~(M2) is not !(C))
  93. *    05.03.1994 -    Some internal bugs removed
  94. *            New internal procedures GregorianSB(),
  95. *            GregorianJHSB(), GregorianJHStartSB() !
  96. *            Extending GregorianEaster() :)
  97. *    11.03.1994 -    Things from 05.03. done in Modula-II and Oberon
  98. *    12.03.1994 -    If __SASC is defined autoinitialization instead of
  99. *            _DateInit() will be used!
  100. *    13.03.1994 -    After studying the SAS C Manual again I decided to
  101. *            check for __SASC_650 instead of __SASC because of
  102. *            the available priorities!
  103. *            Setting the priority of _DateInit() for
  104. *            autoinitialization to 600!
  105. *    15.03.1994 -    Making Date as library
  106. *    16.03.1994 -    Some work on the Autodocs was done,
  107. *            eliminating OldGregorianEaster() by comments
  108. *            (ANSI: STOP bad standards like that there are NO
  109. *             nested comments possible in C!!!).
  110. *    19.03.1994 -    Some work on the Autodocs was done in the M2 Code.
  111. *    20.03.1994 -    Some work on the Autodocs was done in the Oberon Code
  112. *    22.03.1994 -    In JDtoMJD(), MJDtoJD() an L was added to the
  113. *            constant.
  114. *            In GregorianWeekday(), HeisWeekday(),
  115. *            JulianDiffDate(), GregorianDiffDate(),
  116. *            HeisDiffDate(), JDToTime() I have inserted
  117. *            conversions (found with Borland C++ 4.0).
  118. *    24.03.1994 -    Making SunOS4.1.3, SunOS5.3(Solaris2.3) &
  119. *            RS6000 AIX3.2.? binaries with gcc.
  120. *            Eliminating nested commends by inserting a space
  121. *            between / and * (I hate this ANSI C standard
  122. *            feature for commends :(
  123. *    27.03.1994 -    Adding library register assignments to the autodocs.
  124. *    03.04.1994 -    Small fixes for the SAS C++ Compiler
  125. *            Small bug fixed in the M2 version of
  126. *            GregorianEaster()
  127. *    04.04.1994 -    Adding some 'static' keywords.
  128. *    10.04.1994 -    Changing from Shareware to Gift Ware ;-)
  129. *    02.08.1994 -    Small fixes in the Autodocs (thanks to Rita Reichl
  130. *            for correcting my bad english ;-)
  131. *    11.08.1994 -    Again small fixes in the Autodocs!
  132. *    13.11.1994 -    Small fix in JulianWeek(),GregorianWeek(),HeisWeek().
  133. *            Thanks to Jim Rickman for reporting the bug!
  134. *            Small changes in the Autodocs!
  135. *    30.11.1994 -    Fix the bug from 13.11. in M2 and Oberon code.
  136. *    04.12.1994 -    Small fixes in the C-Autodocs.
  137. *    12.12.1994 -    Adding WeekdayText(), MonthText() and internal
  138. *            max().
  139. *    13.12.1994 -    Optimizing WeekdayText() and MonthText()
  140. *    14.12.1994 -    Adding WeekdayShortText() and MonthShortText(),
  141. *            and fixing the french text.
  142. *    17.12.1994 -    Two small changes in the copyright conditions!
  143. *    18.12.1994 -    Fix for Amiga init library
  144. *    10.01.1995 -    Installing TurboText 2.0
  145. *    11.01.1995 -    Found a new (German) book!
  146. *    13.01.1995 -    Introducing release history
  147. *    14.01.1995 -    Introducing to do list
  148. *    15.01.1995 -    Procedures: JDToJulian(), JDToGregorian(),
  149. *            JDToHeis() as dummy, JulianEaster() initiated.
  150. *            Procedure: OldGregorianEaster() removed.
  151. *            Initiating an alternate GregorianEaster() and a
  152. *            dummy HeisEaster().
  153. *    16.01.1995 -    Procedure: GregorianMoonPhase initiated.
  154. *            I decided not longer to support Modula-II and Oberon
  155. *            version, until someone asks for it!
  156. *    17.01.1995 -    Internal procedure: GregorianMoonPhaseHelp.
  157. *            Adding a note to the background.
  158. *            Correcting small bug in autodocs.
  159.     18.01.1995 -    Found a new (German) book!
  160. *    20.01.1995 -    Rita Reichl found David F. Skoll's Reminder3.0 -
  161. *            I am so impressed, that I could not continue my
  162. *            work for one day ;-)
  163. *    21.01.1995 -    I decide to distribute my TextEngine with the date
  164. *            library, when I have finished it.
  165. *    28.01.1995 -    Adding 'static' to GregorianMoonPhaseHelp.
  166. *            Fixing a very small bug.
  167. *    01.02.1995 -    Replacing JulianDaySmaller(), GregorianDaySmaller(),
  168. *            HeisDaySmaller(), JulianDayGreater(),
  169. *            GregorianDayGreater(), HeisDayGreater() with the new
  170. *            CompareDates()!
  171. *            Procedure: CompareTimes() initiated.
  172. *    04.02.1995 -    Adding some things to the autodocs.
  173. *
  174. *****************************************************************************
  175. *
  176. *
  177. */
  178.  
  179. /*
  180. ******* Date/--release-- ****************************************************
  181. *
  182. *   NAME
  183. *    release -- This is the release history of the Date module
  184. *
  185. *   RELEASE
  186. *    13.04.1994 : 33.087 -    V1.0 First release on Aminet3 & SaarAG 707
  187. *    13.08.1994 : 33.088 -    V1.1 Second release on Aminet4, SaarAG 793,
  188. *                     Fred Fish & SimTel
  189. *    18.12.1994 : 33.093 -    V1.2 Third release on Aminet
  190. *    06.02.1995 : 33.100 -    V1.3 Fourth release on Aminet
  191. *
  192. *****************************************************************************
  193. *
  194. *
  195. */
  196.  
  197. /*
  198. *****i* Date/--todo-- *******************************************************
  199. *
  200. *   NAME
  201. *    todo -- This is the 'to do' list of the Date module
  202. *
  203. *   TODO
  204. *    up/down-going of moon and sun
  205. *    other calenders, like the Islamism and the Jewish
  206. *    C++ * parameters, const for * parameters
  207. *    Check valid dates.
  208. *    Textengine
  209. *
  210. *****************************************************************************
  211. *
  212. *
  213. */
  214.  
  215. /*
  216. ******* Date/--background-- *************************************************
  217. *
  218. *   NAME
  219. *    Date -- This module was designed to help calc. calendar dates (V33)
  220. *
  221. *   FUNCTION
  222. *    I know about the date routines in the Amiga-OS(TM), but I decided
  223. *    not to use them because of their limited functionalities and of
  224. *    the portability of this module!
  225. *
  226. *   NOTES
  227. *    A tropical year is 365.2422 days! / 365d, 5h, 48min, 46sec
  228. *    A moon month is 29.53059 days! / 29d, 12h, 44min, 2.9 sec
  229. *    A moon phase is 7.38265 days!
  230. *    All calculations are historical and NOT astronomical!
  231. *
  232. *    (German) Books which helped me creating this library:
  233. *        Kleine Naturwissenschaftliche Bibliothek, Band 23
  234. *        Ewige Kalender
  235. *        A.W. Butkewitsch & M.S. Selikson
  236. *        5. Auflage
  237. *        Teubner, Leipzig 1974
  238. *        ISBN 3-322-00393-0
  239. *
  240. *        Tag und Woche, Monat und Jahr: eine Kulturgeschichte des
  241. *        Kalenders
  242. *        Rudolf Wendorff
  243. *        Westdeutscher, Opladen 1993
  244. *        ISBN 3-531-12417-X
  245. *
  246. *        Kalender und Chronologie: Bekanntes & Unbekanntes aus der
  247. *        Kalenderwissenschaft
  248. *        Heinz Zemanek
  249. *        4. Auflage
  250. *        Oldenbourg, München 1987
  251. *        ISBN 3-486-20447-5
  252. *
  253. *        Meyers Handbuch
  254. *        über das Weltall
  255. *        Karl Schaifers & Gerhard Traving
  256. *        5. Auflage
  257. *        Bibliographisches Institut, Mannheim 1973
  258. *        ISBN 3-411-00940-3
  259. *
  260. *        Astronomische Algorithmen
  261. *        Jean Meeus
  262. *        2. Auflage
  263. *        Johann Ambrosius Barth, Berlin 1994
  264. *        ISBN 3-335-00400-0
  265. *
  266. *        Astronomie mit dem Personal Computer
  267. *        Oliver Montenbruck & Thomas Pfleger
  268. *        2. Auflage
  269. *        Springer, Berlin 1994
  270. *        ISBN 3-540-57701-7
  271. *
  272. *    (English) Books which helped me creating this library:
  273. *        Mathematical Astronomy with a Pocket Calculator
  274. *        Aubrey Jones Fras
  275. *        Unknown (first) Edition
  276. *        David & Charles Newton Abbot, London 1978
  277. *        ISBN 0-7153-7675-6
  278. *
  279. *        Astronomical Algorithms
  280. *        Jean Meeus
  281. *        Unknown Edition (I use the German second edition ;-)
  282. *        Willmann-Bell, Inc., Ruchmond, Virginia (USA) 1991
  283. *        ISBN 0-943396-35-2
  284. *
  285. *   COPYRIGHT
  286. *    This module is Copyright 1994-95 by Kai Hofmann.
  287. *    All rights reserved!
  288. *    For private use, Public Domain, Gift Ware, Freeware and Shareware
  289. *    you could use this module under following conditions:
  290. *    - You send me a little gift (money is very welcome :)
  291. *        For Bank Account see below - but *ONLY* send in DM
  292. *        to this Bank Account!!!
  293. *      Other nice gifts: all Amiga hardware, and I am searching for a
  294. *      good old 1541 (C64 floppy)
  295. *    - You include a notice in your product, that you use this library
  296. *      and that it is Copyright by Kai Hofmann!
  297. *      And send me a free full version of your product!
  298. *    If you want to redistribute this library read the following points:
  299. *    - Redistribution warranty is given to:
  300. *        Fred Fish for his great Amiga-Software-Library
  301. *        The German SAAR AG PD-Library
  302. *        The German AMOK PD-Library
  303. *        All public accessible INTERNET servers and PHONE boxes!
  304. *        All others who do NOT take more than DM 5.- for one disk
  305. *        ALL others who do NOT take more than DM 50.- for one CD
  306. *    For commercial use send me DM 200.- and a free version of your
  307. *    product!
  308. *    But if you are Apple or Microsoft you have to send (20000.- US$)
  309. *
  310. *   DISCLAIMER
  311. *
  312. *      THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
  313. *   APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
  314. *   HOLDER AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
  315. *   OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
  316. *   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  317. *   PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
  318. *   PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE
  319. *   COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  320. *
  321. *      IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  322. *   WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY REDISTRIBUTE THE
  323. *   PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
  324. *   GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  325. *   USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS
  326. *   OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR
  327. *   THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  328. *   PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  329. *   POSSIBILITY OF SUCH DAMAGES.
  330. *
  331. *   ADDITIONAL INFORMATIONS
  332. *    I have tried to make portable/useful and I hope bugfree software
  333. *    for eternity - but this seems to be impossible (sorry!) :)
  334. *    So I hope you will pay a fee for this.
  335. *
  336. *   AUTHOR
  337. *    Kai Hofmann
  338. *    Arberger Heerstraße 92
  339. *    28307 Bremen
  340. *    Germany
  341. *    EMail: i07m@zfn.uni-bremen.de
  342. *           i07m@informatik.uni-bremen.de
  343. *    IRC  : PowerStat
  344. *    WWW  : http://www.informatik.uni-bremen.de/~i07m/
  345. *    (no phone - I hate it!)
  346. *
  347. *    Bank account : 1203 7503
  348. *    Account owner: Kai Hofmann
  349. *    Bank code    : 290 501 01
  350. *    Bank name    : Sparkasse in Bremen
  351. *
  352. *    THANX
  353. *    Thanx are going to the following people:
  354. *    Daniel Amor        - For his hint about the Oberon-2 SHORT
  355. *                  command
  356. *    Heinz Zemanek        - For his great book
  357. *    Christian Schaefer    - For spending time on this lib with his
  358. *                  Borland C++ 4.0 compiler
  359. *    Rita Reichl        - For correcting my bad english ;-)
  360. *    Jim Rickman        - For reporting a bug
  361. *
  362. *****************************************************************************
  363. *
  364. *
  365. */
  366.  
  367.  
  368.  #include <stdlib.h> /* abs()   */
  369.  #include <math.h>   /* floor() */
  370.  #include <string.h> /* strcpy(), strlen() */
  371.  #ifndef __SASC_650
  372.    #undef __MakeLib
  373.  #endif
  374.  #ifdef _AMIGA
  375.    #define _ISO8859_Latin1
  376.    #include <proto/exec.h>
  377.    #include <proto/locale.h>
  378.  #endif
  379.  #include "Date.h"
  380.  
  381.  
  382.  #ifdef _AMIGA
  383.    #ifdef __SASC_650
  384.      extern struct Library *LocaleBase;
  385.    #else
  386.      static struct Library *LocaleBase = NULL;
  387.    #endif
  388.    static struct Locale  *locale   = NULL;
  389.    static unsigned short  wlen     = 0, abwlen = 0,
  390.                           mlen     = 0, abmlen = 0;
  391.    static ULONG           DAYS[]   = {DAY_1,DAY_2,DAY_3,DAY_4,DAY_5,DAY_6,DAY_7},
  392.                           MONS[]   = {MON_1,MON_2,MON_3,MON_4,MON_5,MON_6,MON_7,MON_8,MON_9,MON_10,MON_11,MON_12},
  393.                           ABDAYS[] = {ABDAY_1,ABDAY_2,ABDAY_3,ABDAY_4,ABDAY_5,ABDAY_6,ABDAY_7},
  394.                           ABMONS[] = {ABMON_1,ABMON_2,ABMON_3,ABMON_4,ABMON_5,ABMON_6,ABMON_7,ABMON_8,ABMON_9,ABMON_10,ABMON_11,ABMON_12};
  395.    #ifdef __MakeLib
  396.      #include <exec/libraries.h>
  397.  
  398.      void __regargs __chkabort(void)
  399.       {}
  400.  
  401.      void __regargs _CXBRK(void)
  402.       {}
  403.    #endif
  404.  #endif
  405.  
  406.  
  407.  static unsigned short    BeforeGregorianDay = 4,
  408.             BeforeGregorianMonth = 10,
  409.             AfterGregorianDay = 15,
  410.             AfterGregorianMonth = 10,
  411.             StartHeisDay = 1,
  412.             StartHeisMonth = 1;
  413.  static int        BeforeGregorianYear = 1582,
  414.             AfterGregorianYear = 1582,
  415.             StartHeisYear = 3200;
  416.  
  417.  /* ----------------------------------------------------------------------- */
  418.  
  419.  #ifdef __MakeLib
  420.    bool __saveds __asm JulianLeapYear(register __d0 const int year)
  421.  #else
  422.    bool JulianLeapYear(const int year)
  423.  #endif
  424.  
  425. /*
  426. ******* Date/JulianLeapYear *************************************************
  427. *
  428. *   NAME
  429. *    JulianLeapYear -- Checks if a year is a leap year. (V33)
  430. *
  431. *   SYNOPSIS
  432. *    leapyear = JulianLeapYear(year);
  433. *       d0               d0
  434. *
  435. *    bool JulianLeapYear(const int year);
  436. *
  437. *   FUNCTION
  438. *    JulianLeapYear checks if a year is a leap year in the julian calendar
  439. *    For years after Chr. it checks if the year is devideable by 4.
  440. *    For years before Chr. a leap year must have a modulo 4 value of 1
  441. *
  442. *   INPUTS
  443. *    year - The year which should be checked (from -32768 to 32767)
  444. *        I think only values from -7 to 32767 are valid, because of
  445. *        the variant that was done on -8 by Augustus and other things!
  446. *
  447. *   RESULT
  448. *    leapyear - TRUE if the year is a leap year, otherwise false.
  449. *
  450. *   EXAMPLE
  451. *    ...
  452. *    if (JulianLeapYear(1994))
  453. *      printf("leap year!\n");
  454. *    else
  455. *      printf("no leap year!\n");
  456. *    ...
  457. *
  458. *   NOTES
  459. *    A year is 365.25 days long!
  460. *    Use this function only for values from -7 to 1582!
  461. *
  462. *   BUGS
  463. *    No known bugs.
  464. *
  465. *   SEE ALSO
  466. *    GregorianLeapYear(),HeisLeapYear()
  467. *
  468. *****************************************************************************
  469. *
  470. *
  471. */
  472.  
  473.   {if (year <= 0)
  474.      return((bool)(abs(year) % 4 == 1));
  475.    else
  476.      return((bool)(year % 4 == 0));
  477.   }
  478.  
  479.  
  480.  #ifdef __MakeLib
  481.    bool __saveds __asm GregorianLeapYear(register __d0 const int year)
  482.  #else
  483.    bool GregorianLeapYear(const int year)
  484.  #endif
  485.  
  486. /*
  487. ******* Date/GregorianLeapYear **********************************************
  488. *
  489. *   NAME
  490. *    GregorianLeapYear -- Checks if a year is a leap year. (V33)
  491. *
  492. *   SYNOPSIS
  493. *    leapyear = GregorianLeapYear(year);
  494. *       d0                  d0
  495. *
  496. *    bool GregorianLeapYear(const int year);
  497. *
  498. *   FUNCTION
  499. *    GregorianLeapYear checks if a year is a leap year.
  500. *    For years after 1582 all years devideable by 4 are leap years,
  501. *    without years devideable by 100, but years devideable by 400
  502. *    are leap years again!
  503. *    For years before 1582 see JulianLeapYear().
  504. *
  505. *   INPUTS
  506. *    year - The year which should be checked (from -32768 to 32767)
  507. *        I think only values from -7 to 3200 are valid, because of
  508. *        the variant that was done on -8 by Augustus and other things!
  509. *
  510. *   RESULT
  511. *    leapyear - TRUE if the year is a leap year, otherwise false.
  512. *
  513. *   EXAMPLE
  514. *    ...
  515. *    if (GregorianLeapYear(1994))
  516. *      printf("leap year!\n");
  517. *    else
  518. *      printf("no leap year!\n");
  519. *    ...
  520. *
  521. *   NOTES
  522. *    A year is 365.2425 days long!
  523. *    Use this function only for values from -7 to 3199!
  524. *
  525. *   BUGS
  526. *    No known bugs.
  527. *
  528. *   SEE ALSO
  529. *    JulianLeapYear(),HeisLeapYear()
  530. *
  531. *****************************************************************************
  532. *
  533. *
  534. */
  535.  
  536.   {if (year < BeforeGregorianYear)
  537.      {/* Year of the Gregorian reform */
  538.       return(JulianLeapYear(year));
  539.      }
  540.    else
  541.      {/* AfterGregorianYear reform */
  542.       return((bool)((year % 4 == 0) && ((year % 100 > 0) || (year % 400 == 0))));
  543.      }
  544.   }
  545.  
  546.  
  547.  #ifdef __MakeLib
  548.    bool __saveds __asm HeisLeapYear(register __d0 const int year)
  549.  #else
  550.    bool HeisLeapYear(const int year)
  551.  #endif
  552.  
  553. /*
  554. ******* Date/HeisLeapYear ***************************************************
  555. *
  556. *   NAME
  557. *    HeisLeapYear -- Checks if a year is a leap year. (V33)
  558. *
  559. *   SYNOPSIS
  560. *    leapyear = HeisLeapYear(year);
  561. *       d0             d0
  562. *
  563. *    bool HeisLeapYear(const int year);
  564. *
  565. *   FUNCTION
  566. *    HeisLeapYear checks if a year is a leap year.
  567. *    For years after 1582 see GregorianLeapYear(),
  568. *    The correction from N. Heis says, that all years devideable by
  569. *    3200 are no longer leap years!
  570. *    For years before 1582 see JulianLeapYear().
  571. *
  572. *   INPUTS
  573. *    year - The year which should be checked (from -32768 to 32767)
  574. *        I think only values from -7 to 32767 are valid, because of
  575. *        the variant that was done on -8 by Augustus and other things!
  576. *
  577. *   RESULT
  578. *    leapyear - TRUE if the year is a leap year, otherwise false.
  579. *
  580. *   EXAMPLE
  581. *    ...
  582. *    if (HeisLeapYear(1994))
  583. *      printf("leap year!\n");
  584. *    else
  585. *      printf("no leap year!\n");
  586. *    ...
  587. *
  588. *   NOTES
  589. *    A year is now 365.2421875 days!
  590. *    Use this function only for values from -7 to 8000!
  591. *
  592. *   BUGS
  593. *    No known bugs.
  594. *
  595. *   SEE ALSO
  596. *    JulianLeapYear(),GregorianLeapYear()
  597. *
  598. *****************************************************************************
  599. *
  600. *
  601. */
  602.  
  603.   {if (year < BeforeGregorianYear)
  604.      {/* Year of the Gregorian reform */
  605.       return(JulianLeapYear(year));
  606.      }
  607.    else
  608.      {/* year >= AfterGregorianYear */
  609.       if (year % 3200 == 0)
  610.         {/* Correction from N. Heis */
  611.          return(false);
  612.         }
  613.       else
  614.         {/* (no leap year all 3200 years) */
  615.          return(GregorianLeapYear(year));
  616.         }
  617.      }
  618.   }
  619.  
  620.  /* ----------------------------------------------------------------------- */
  621.  
  622.  #ifdef __MakeLib
  623.    unsigned short __saveds __asm JulianMonthDays(register __d0 const unsigned short month, register __d1 const int year)
  624.  #else
  625.    unsigned short JulianMonthDays(const unsigned short month, const int year)
  626.  #endif
  627.  
  628. /*
  629. ******* Date/JulianMonthDays ************************************************
  630. *
  631. *   NAME
  632. *    JulianMonthDays -- Gives back the number of days of a month. (V33)
  633. *
  634. *   SYNOPSIS
  635. *    days = JulianMonthDays(month,year);
  636. *     d0            d0    d1
  637. *
  638. *    unsigned short JulianMonthDays(const unsigned short month,
  639. *        const int year);
  640. *
  641. *   FUNCTION
  642. *    JulianMonthDays gives you back the number of days a month in
  643. *    a specified year has.
  644. *
  645. *   INPUTS
  646. *    month - The month from which you want to get the number of days.
  647. *    year  - The year in which the month is.
  648. *
  649. *   RESULT
  650. *    days - The number of days the month uses, or 0 if you use
  651. *        a wrong month.
  652. *
  653. *   EXAMPLE
  654. *    ...
  655. *    days = JulianMonthDays(1,1994);
  656. *    printf("Days of January 1994 : %d\n",days);
  657. *    ...
  658. *
  659. *   NOTES
  660. *    It is better only to use this function for years from -7 to 09.1582!
  661. *
  662. *   BUGS
  663. *    No known bugs.
  664. *
  665. *   SEE ALSO
  666. *    JulianLeapYear(),GregorianMonthDays(),HeisMonthDays()
  667. *
  668. *****************************************************************************
  669. *
  670. *
  671. */
  672.  
  673.   {switch (month)
  674.      {case  1 :
  675.       case  3 :
  676.       case  5 :
  677.       case  7 :
  678.       case  8 :
  679.       case 10 :
  680.       case 12 : return(31);
  681.       case  4 :
  682.       case  6 :
  683.       case  9 :
  684.       case 11 : return(30);
  685.       case  2 : if (JulianLeapYear(year))
  686.                   return(29);
  687.                 else
  688.                   if (!JulianLeapYear(year))
  689.                     return(28);
  690.       default : return(0);
  691.      }
  692.   }
  693.  
  694.  
  695.  #ifdef __MakeLib
  696.    unsigned short __saveds __asm GregorianMonthDays(register __d0 const unsigned short month, register __d1 const int year)
  697.  #else
  698.    unsigned short GregorianMonthDays(const unsigned short month, const int year)
  699.  #endif
  700.  
  701. /*
  702. ******* Date/GregorianMonthDays *********************************************
  703. *
  704. *   NAME
  705. *    GregorianMonthDays -- Gives back the number of days of a month. (V33)
  706. *
  707. *   SYNOPSIS
  708. *    days = GregorianMonthDays(month,year);
  709. *     d0               d0    d1
  710. *
  711. *    unsigned short GregorianMonthDays(const unsigned short month,
  712. *        const int year);
  713. *
  714. *   FUNCTION
  715. *    GregorianMonthDays gives you back the number of days a month in
  716. *    a specified year has.
  717. *    For the year 1582 and the month 10 there are only 21 days,
  718. *    because of the Gregorian-reform 10 days are deleted from
  719. *    the month (for more - look out for books about this!)
  720. *
  721. *   INPUTS
  722. *    month - The month from which you want to get the number of days.
  723. *    year  - The year in which the month is.
  724. *
  725. *   RESULT
  726. *    days - The number of days the month uses, or 0 if you use
  727. *        a wrong month.
  728. *
  729. *   EXAMPLE
  730. *    ...
  731. *    days = GregorianMonthDays(1,1994);
  732. *    printf("Days of January 1994 : %d\n",days);
  733. *    ...
  734. *
  735. *   NOTES
  736. *    Use this function only for years from -7 to 3199!
  737. *
  738. *   BUGS
  739. *    none.
  740. *
  741. *   SEE ALSO
  742. *    GregorianLeapYear(),JulianMonthDays(),HeisMonthDays()
  743. *
  744. *****************************************************************************
  745. *
  746. *
  747. */
  748.  
  749.   {if ((year == AfterGregorianYear) && (month == AfterGregorianMonth))
  750.      {/* 10 days canceled by Gregor XIII
  751.                 in countries who chnaged later are more days */
  752.       return((unsigned short)(31-((AfterGregorianDay-BeforeGregorianDay)-1)));
  753.      }
  754.    else
  755.      if ((month == 2) && GregorianLeapYear(year))
  756.        return(29);
  757.      else
  758.        if ((month == 2) && (!GregorianLeapYear(year)))
  759.          return(28);
  760.        else
  761.          {/* use Julian function for other calcs. */
  762.           return(JulianMonthDays(month,year));
  763.          }
  764.   }
  765.  
  766.  
  767.  #ifdef __MakeLib
  768.    unsigned short __saveds __asm HeisMonthDays(register __d0 const unsigned short month, register __d1 const int year)
  769.  #else
  770.    unsigned short HeisMonthDays(const unsigned short month, const int year)
  771.  #endif
  772.  
  773. /*
  774. ******* Date/HeisMonthDays **************************************************
  775. *
  776. *   NAME
  777. *    HeisMonthDays -- Gives back the number of days of a month. (V33)
  778. *
  779. *   SYNOPSIS
  780. *    days = HeisMonthDays(month,year);
  781. *     d0              d0    d1
  782. *
  783. *    unsigned short HeisMonthDays(const unsigned short month,
  784. *        const int year);
  785. *
  786. *   FUNCTION
  787. *    HeisMonthDays gives you back the number of days a month in
  788. *    a specified year has.
  789. *    For the year 1582 and the month 10 there are only 21 days,
  790. *    because of the Gregorian-reform 10 days are deleted from
  791. *    the month (for more - look out for books about this!)
  792. *
  793. *   INPUTS
  794. *    month - The month from which you want to get the number of days.
  795. *    year  - The year in which the month is.
  796. *
  797. *   RESULT
  798. *    days - The number of days the month uses, or 0 if you use
  799. *        a wrong month.
  800. *
  801. *   EXAMPLE
  802. *    ...
  803. *    days = HeisMonthDays(1,1994);
  804. *    printf("Days of January 1994 : %d\n",days);
  805. *    ...
  806. *
  807. *   NOTES
  808. *    Use this function only for years from -7 to 8000!
  809. *
  810. *   BUGS
  811. *    See GregorianMonthDays!
  812. *
  813. *   SEE ALSO
  814. *    HeisLeapYear(),JulianMonthDays(),GregorianMonthDays()
  815. *
  816. *****************************************************************************
  817. *
  818. *
  819. */
  820.  
  821.   {if ((month == 2) && HeisLeapYear(year))
  822.      return(29);
  823.    else
  824.      if ((month == 2) && (!HeisLeapYear(year)))
  825.        return(28);
  826.      else
  827.        {/* use Gregorian function for other calcs */
  828.         return(GregorianMonthDays(month,year));
  829.        }
  830.   }
  831.  
  832.  /* ----------------------------------------------------------------------- */
  833.  
  834.  #ifdef __MakeLib
  835.    unsigned int __saveds __asm JulianYearDays(register __d0 const int year)
  836.  #else
  837.    unsigned int JulianYearDays(const int year)
  838.  #endif
  839.  
  840. /*
  841. ******* Date/JulianYearDays *************************************************
  842. *
  843. *   NAME
  844. *    JulianYearDays -- Gives back the number of days in a year. (V33)
  845. *
  846. *   SYNOPSIS
  847. *    days = JulianYearDays(year);
  848. *     d0               d0
  849. *
  850. *    unsigned int JulianYearDays(const int year);
  851. *
  852. *   FUNCTION
  853. *    JulianYearDays gives you back the number of days in
  854. *    a specified year.
  855. *
  856. *   INPUTS
  857. *    year  - The year in which to count the days.
  858. *
  859. *   RESULT
  860. *    days - The number of days the year uses.
  861. *
  862. *   EXAMPLE
  863. *    ...
  864. *    days = JulianYearDays(1994);
  865. *    printf("Days of 1994 : %d\n",days);
  866. *    ...
  867. *
  868. *   NOTES
  869. *    It is better only to use this function for years from -7 to 1581!
  870. *
  871. *   BUGS
  872. *    No known bugs.
  873. *
  874. *   SEE ALSO
  875. *    JulianMonthDays(),GregorianYearDays(),HeisYearDays()
  876. *
  877. *****************************************************************************
  878. *
  879. *
  880. */
  881.  
  882.  {unsigned short month;
  883.   unsigned int days;
  884.  
  885.   days = 0;
  886.   for (month=1; month<=12; month++)
  887.     {/* add the days of all 12 month */
  888.      days += JulianMonthDays(month,year);
  889.     }
  890.   return(days);
  891.  }
  892.  
  893.  
  894.  #ifdef __MakeLib
  895.    unsigned int __saveds __asm GregorianYearDays(register __d0 const int year)
  896.  #else
  897.    unsigned int GregorianYearDays(const int year)
  898.  #endif
  899.  
  900. /*
  901. ******* Date/GregorianYearDays **********************************************
  902. *
  903. *   NAME
  904. *    GregorianYearDays -- Gives back the number of days in a year. (V33)
  905. *
  906. *   SYNOPSIS
  907. *    days = GregorianYearDays(year);
  908. *     d0              d0
  909. *
  910. *    unsigned int GregorianYearDays(const int year);
  911. *
  912. *   FUNCTION
  913. *    GregorianYearDays gives you back the number of days in
  914. *    a specified year.
  915. *
  916. *   INPUTS
  917. *    year  - The year in which to count the days.
  918. *
  919. *   RESULT
  920. *    days - The number of days the year uses.
  921. *
  922. *   EXAMPLE
  923. *    ...
  924. *    days = GregorianYearDays(1994);
  925. *    printf("Days of 1994 : %d\n",days);
  926. *    ...
  927. *
  928. *   NOTES
  929. *    It is better only to use this function for years from -7 to 3199!
  930. *
  931. *   BUGS
  932. *    No known bugs.
  933. *
  934. *   SEE ALSO
  935. *    GregorianMonthDays(),JulianYearDays(),HeisYearDays()
  936. *
  937. *****************************************************************************
  938. *
  939. *
  940. */
  941.  
  942.  {unsigned short month;
  943.   unsigned int days;
  944.  
  945.   days = 0;
  946.   for (month=1; month<=12; month++)
  947.     {/* add the days of all 12 month */
  948.      days += GregorianMonthDays(month,year);
  949.     }
  950.   return(days);
  951.  }
  952.  
  953.  
  954.  #ifdef __MakeLib
  955.    unsigned int __saveds __asm HeisYearDays(register __d0 const int year)
  956.  #else
  957.    unsigned int HeisYearDays(const int year)
  958.  #endif
  959.  
  960. /*
  961. ******* Date/HeisYearDays ***************************************************
  962. *
  963. *   NAME
  964. *    HeisYearDays -- Gives back the number of days in a year. (V33)
  965. *
  966. *   SYNOPSIS
  967. *    days = HeisYearDays(year);
  968. *     d0             d0
  969. *
  970. *    unsigned int HeisYearDays(const int year);
  971. *
  972. *   FUNCTION
  973. *    HeisYearDays gives you back the number of days in
  974. *    a specified year.
  975. *
  976. *   INPUTS
  977. *    year  - The year in which to count the days.
  978. *
  979. *   RESULT
  980. *    days - The number of days the year uses.
  981. *
  982. *   EXAMPLE
  983. *    ...
  984. *    days = HeisYearDays(1994);
  985. *    printf("Days of 1994 : %d\n",days);
  986. *    ...
  987. *
  988. *   NOTES
  989. *    It is better only to use this function for years from -7 to 8000!
  990. *
  991. *   BUGS
  992. *    No known bugs.
  993. *
  994. *   SEE ALSO
  995. *    HeisMonthDays(),JulianYearDays(),GregorianYearDays()
  996. *
  997. *****************************************************************************
  998. *
  999. *
  1000. */
  1001.  
  1002.  {unsigned short month;
  1003.   unsigned int days;
  1004.  
  1005.   days = 0;
  1006.   for (month=1; month<=12; month++)
  1007.     {/* add the days of all 12 month */
  1008.      days += HeisMonthDays(month,year);
  1009.     }
  1010.   return(days);
  1011.  }
  1012.  
  1013.  /* ----------------------------------------------------------------------- */
  1014.  
  1015.  #ifdef __MakeLib
  1016.    short __saveds __asm CompareDates(register __d0 const unsigned short day1, register __d1 const unsigned short month1, register __d2 const int year1, register __d3 const unsigned short day2, register __d4 const unsigned short month2, register __d5 const int year2)
  1017.  #else
  1018.    short CompareDates(const unsigned short day1, const unsigned short month1, const int year1, const unsigned short day2, const unsigned short month2, const int year2)
  1019.  #endif
  1020.  
  1021. /*
  1022. ******* Date/CompareDates ***************************************************
  1023. *
  1024. *   NAME
  1025. *    CompareDates -- Compares date1 with date2. (V33.100)
  1026. *
  1027. *   SYNOPSIS
  1028. *    compare = CompareDates(day1,month1,year1,day2,month2,year2);
  1029. *      d0            d0    d1    d2    d3    d4    d5
  1030. *
  1031. *    short CompareDates(const unsigned short day1,
  1032. *        const unsigned short month1, const int year1,
  1033. *        const unsigned short day2, const unsigned short month2,
  1034. *        const int year2);
  1035. *
  1036. *   FUNCTION
  1037. *    CompareDates compares date1 with date2.
  1038. *
  1039. *   INPUTS
  1040. *    day1   - day of the first date
  1041. *    month1 - month of the first date
  1042. *    year1  - year of the first date
  1043. *    day2   - day of the second date
  1044. *    month2 - month of the second month
  1045. *    year2  - year of the second date
  1046. *
  1047. *   RESULT
  1048. *    compare - -1 : date1 < date2
  1049. *           0 : date1 = date2
  1050. *           1 : date1 > date2
  1051. *
  1052. *   EXAMPLE
  1053. *    ...
  1054. *    if (CompareDates(18,9,1970,22,1,1994) == -1)
  1055. *      printf("<\n");
  1056. *    else
  1057. *      printf(">=\n");
  1058. *    ...
  1059. *
  1060. *   NOTES
  1061. *    It is better only to use this function for years from -7 to 8000!
  1062. *    There is no need for different versions for Julian, Gregorian and
  1063. *    Heis dates!
  1064. *
  1065. *   BUGS
  1066. *    There is no check if the dates are valid!
  1067. *
  1068. *   SEE ALSO
  1069. *    CompareTimes()
  1070. *
  1071. *****************************************************************************
  1072. *
  1073. *
  1074. */
  1075.  
  1076.  {
  1077.   if (year1 < year2)
  1078.     return(-1);
  1079.   else if (year1 > year2)
  1080.     return(1);
  1081.   else if (month1 < month2)
  1082.     return(-1);
  1083.   else if (month1 > month2)
  1084.     return(1);
  1085.   else if (day1 < day2)
  1086.     return(-1);
  1087.   else if (day1 > day2)
  1088.     return(1);
  1089.   else
  1090.     return(0);
  1091.  }
  1092.  
  1093.  /* ----------------------------------------------------------------------- */
  1094.  
  1095.  #ifdef __MakeLib
  1096.    bool __saveds __asm JulianDaySmaller(register __d0 const unsigned short day1, register __d1 const unsigned short month1, register __d2 const int year1, register __d3 const unsigned short day2, register __d4 const unsigned short month2, register __d5 const int year2)
  1097.  #else
  1098.    bool JulianDaySmaller(const unsigned short day1, const unsigned short month1, const int year1, const unsigned short day2, const unsigned short month2, const int year2)
  1099.  #endif
  1100.  
  1101. /*
  1102. *****i* Date/JulianDaySmaller ***********************************************
  1103. *
  1104. *   NAME
  1105. *    JulianDaySmaller -- Checks if date1 is smaller than date2. (V33)
  1106. *
  1107. *   SYNOPSIS
  1108. *    smaller = JulianDaySmaller(day1,month1,year1,day2,month2,year2);
  1109. *      d0                d0    d1    d2    d3    d4    d5
  1110. *
  1111. *    bool JulianDaySmaller(const unsigned short day1,
  1112. *        const unsigned short month1, const int year1,
  1113. *        const unsigned short day2, const unsigned short month2,
  1114. *        const int year2);
  1115. *
  1116. *   FUNCTION
  1117. *    JulianDaySmaller test if date1 is smaller than date2.
  1118. *
  1119. *   INPUTS
  1120. *    day1   - day of the first date
  1121. *    month1 - month of the first date
  1122. *    year1  - year of the first date
  1123. *    day2   - day of the second date
  1124. *    month2 - month of the second month
  1125. *    year2  - year of the second date
  1126. *
  1127. *   RESULT
  1128. *    smaller - This is TRUE is date1 < date2 otherwise it's FALSE.
  1129. *
  1130. *   EXAMPLE
  1131. *    ...
  1132. *    if (JulianDaySmaller(18,9,1970,22,1,1994))
  1133. *      printf("<\n");
  1134. *    else
  1135. *      printf(">=\n");
  1136. *    ...
  1137. *
  1138. *   NOTES
  1139. *    It is better only to use this function for years from -7 to 1582!
  1140. *    This function is not longer needed - use CompareDates() !
  1141. *
  1142. *   BUGS
  1143. *    No known bugs.
  1144. *
  1145. *   SEE ALSO
  1146. *    GregorianDaySmaller(),HeisDaySmaller(),CompareDates()
  1147. *
  1148. *****************************************************************************
  1149. *
  1150. *
  1151. */
  1152.  
  1153.  {
  1154.   return((bool)(CompareDates(day1,month1,year1,day2,month2,year2) == -1));
  1155.  }
  1156.  
  1157.  
  1158.  #ifdef __MakeLib
  1159.    bool __saveds __asm GregorianDaySmaller(register __d0 const unsigned short day1, register __d1 const unsigned short month1, register __d2 const int year1, register __d3 const unsigned short day2, register __d4 const unsigned short month2, register __d5 const int year2)
  1160.  #else
  1161.    bool GregorianDaySmaller(const unsigned short day1, const unsigned short month1, const int year1, const unsigned short day2, const unsigned short month2, const int year2)
  1162.  #endif
  1163.  
  1164. /*
  1165. *****i* Date/GregorianDaySmaller ********************************************
  1166. *
  1167. *   NAME
  1168. *    GregorianDaySmaller -- Checks if date1 is smaller than date2. (V33)
  1169. *
  1170. *   SYNOPSIS
  1171. *    smaller = GregorianDaySmaller(day1,month1,year1,day2,month2,year2);
  1172. *      d0                   d0    d1    d2    d3    d4    d5
  1173. *
  1174. *    bool GregorianDaySmaller(const unsigned short day1,
  1175. *        const unsigned short month1, const int year1,
  1176. *        const unsigned short day2, const unsigned short month2,
  1177. *        const int year2);
  1178. *
  1179. *   FUNCTION
  1180. *    GregorianDaySmaller test if date1 is smaller than date2.
  1181. *
  1182. *   INPUTS
  1183. *    day1   - day of the first date
  1184. *    month1 - month of the first date
  1185. *    year1  - year of the first date
  1186. *    day2   - day of the second date
  1187. *    month2 - month of the second month
  1188. *    year2  - year of the second date
  1189. *
  1190. *   RESULT
  1191. *    smaller - This is TRUE is date1 < date2 otherwise it's FALSE.
  1192. *
  1193. *   EXAMPLE
  1194. *    ...
  1195. *    if (GregorianDaySmaller(18,9,1970,22,1,1994))
  1196. *      printf("<\n");
  1197. *    else
  1198. *      printf(">=\n");
  1199. *    ...
  1200. *
  1201. *   NOTES
  1202. *    It is better only to use this function for years from -7 to 3200!
  1203. *    This function is not longer needed - use CompareDates() !
  1204. *
  1205. *   BUGS
  1206. *    No known bugs.
  1207. *
  1208. *   SEE ALSO
  1209. *    JulianDaySmaller(),HeisDaySmaller(),CompareDates()
  1210. *
  1211. *****************************************************************************
  1212. *
  1213. *
  1214. */
  1215.  
  1216.  {
  1217.   return((bool)(CompareDates(day1,month1,year1,day2,month2,year2) == -1));
  1218.  }
  1219.  
  1220.  
  1221.  #ifdef __MakeLib
  1222.    bool __saveds __asm HeisDaySmaller(register __d0 const unsigned short day1, register __d1 const unsigned short month1, register __d2 const int year1, register __d3 const unsigned short day2, register __d4 const unsigned short month2, register __d5 const int year2)
  1223.  #else
  1224.    bool HeisDaySmaller(const unsigned short day1, const unsigned short month1, const int year1, const unsigned short day2, const unsigned short month2, const int year2)
  1225.  #endif
  1226.  
  1227. /*
  1228. *****i* Date/HeisDaySmaller *************************************************
  1229. *
  1230. *   NAME
  1231. *    HeisDaySmaller -- Checks if date1 is smaller than date2. (V33)
  1232. *
  1233. *   SYNOPSIS
  1234. *    smaller = HeisDaySmaller(day1,month1,year1,day2,month2,year2);
  1235. *      d0              d0    d1    d2    d3    d4    d5
  1236. *
  1237. *    bool HeisDaySmaller(const unsigned short day1,
  1238. *        const unsigned short month1, const int year1,
  1239. *        const unsigned short day2, const unsigned short month2,
  1240. *        const int year2);
  1241. *
  1242. *   FUNCTION
  1243. *    HeisDaySmaller test if date1 is smaller than date2.
  1244. *
  1245. *   INPUTS
  1246. *    day1   - day of the first date
  1247. *    month1 - month of the first date
  1248. *    year1  - year of the first date
  1249. *    day2   - day of the second date
  1250. *    month2 - month of the second month
  1251. *    year2  - year of the second date
  1252. *
  1253. *   RESULT
  1254. *    smaller - This is TRUE is date1 < date2 otherwise it's FALSE.
  1255. *
  1256. *   EXAMPLE
  1257. *    ...
  1258. *    if (HeisDaySmaller(18,9,1970,22,1,1994))
  1259. *      printf("<\n");
  1260. *    else
  1261. *      printf(">=\n");
  1262. *    ...
  1263. *
  1264. *   NOTES
  1265. *    It is better only to use this function for years from -7 to 8000!
  1266. *    This function is not longer needed - use CompareDates() !
  1267. *
  1268. *   BUGS
  1269. *    No known bugs.
  1270. *
  1271. *   SEE ALSO
  1272. *    JulianDaySmaller(),GregorianDaySmaller(),CompareDates()
  1273. *
  1274. *****************************************************************************
  1275. *
  1276. *
  1277. */
  1278.  
  1279.  {
  1280.   return((bool)(CompareDates(day1,month1,year1,day2,month2,year2) == -1));
  1281.  }
  1282.  
  1283.  /* ----------------------------------------------------------------------- */
  1284.  
  1285.  #ifdef __MakeLib
  1286.    bool __saveds __asm JulianDayGreater(register __d0 const unsigned short day1, register __d1 const unsigned short month1, register __d2 const int year1, register __d3 const unsigned short day2, register __d4 const unsigned short month2, register __d5 const int year2)
  1287.  #else
  1288.    bool JulianDayGreater(const unsigned short day1, const unsigned short month1, const int year1, const unsigned short day2, const unsigned short month2, const int year2)
  1289.  #endif
  1290.  
  1291. /*
  1292. *****i* Date/JulianDayGreater ***********************************************
  1293. *
  1294. *   NAME
  1295. *    JulianDayGreater -- Checks if date1 is greater than date2. (V33)
  1296. *
  1297. *   SYNOPSIS
  1298. *    greater = JulianDayGreater(day1,month1,year1,day2,month2,year2);
  1299. *      d0                d0    d1    d2    d3    d4    d5
  1300. *
  1301. *    bool JulianDayGreater(const unsigned short day1,
  1302. *        const unsigned short month1, const int year1,
  1303. *        const unsigned short day2, const unsigned short month2,
  1304. *        const int year2);
  1305. *
  1306. *   FUNCTION
  1307. *    JulianDayGreater test if date1 is greater than date2.
  1308. *
  1309. *   INPUTS
  1310. *    day1   - day of the first date
  1311. *    month1 - month of the first date
  1312. *    year1  - year of the first date
  1313. *    day2   - day of the second date
  1314. *    month2 - month of the second month
  1315. *    year2  - year of the second date
  1316. *
  1317. *   RESULT
  1318. *    greater - This is TRUE is date1 > date2 otherwise it's FALSE.
  1319. *
  1320. *   EXAMPLE
  1321. *    ...
  1322. *    if (JulianDayGreater(18,9,1970,22,1,1994))
  1323. *      printf(">\n");
  1324. *    else
  1325. *      printf("<=\n");
  1326. *    ...
  1327. *
  1328. *   NOTES
  1329. *    It is better only to use this function for years from -7 to 1582!
  1330. *    This function is not longer needed - use CompareDates() !
  1331. *
  1332. *   BUGS
  1333. *    No known bugs.
  1334. *
  1335. *   SEE ALSO
  1336. *    GregorianDayGreater(),HeisDayGreater(),CompareDates()
  1337. *
  1338. *****************************************************************************
  1339. *
  1340. *
  1341. */
  1342.  
  1343.  {
  1344.   return((bool)(CompareDates(day1,month1,year1,day2,month2,year2) == 1));
  1345.  }
  1346.  
  1347.  
  1348.  #ifdef __MakeLib
  1349.    bool __saveds __asm GregorianDayGreater(register __d0 const unsigned short day1, register __d1 const unsigned short month1, register __d2 const int year1, register __d3 const unsigned short day2, register __d4 const unsigned short month2, register __d5 const int year2)
  1350.  #else
  1351.    bool GregorianDayGreater(const unsigned short day1, const unsigned short month1, const int year1, const unsigned short day2, const unsigned short month2, const int year2)
  1352.  #endif
  1353.  
  1354. /*
  1355. *****i* Date/GregorianDayGreater ********************************************
  1356. *
  1357. *   NAME
  1358. *    GregorianDayGreater -- Checks if date1 is greater than date2. (V33)
  1359. *
  1360. *   SYNOPSIS
  1361. *    greater = GregorianDayGreater(day1,month1,year1,day2,month2,year2);
  1362. *      d0                   d0    d1    d2    d3    d4    d5
  1363. *
  1364. *    bool GregorianDayGreater(const unsigned short day1,
  1365. *        const unsigned short month1, const int year1,
  1366. *        const unsigned short day2, const unsigned short month2,
  1367. *        const int year2);
  1368. *
  1369. *   FUNCTION
  1370. *    GregorianDayGreater test if date1 is greater than date2.
  1371. *
  1372. *   INPUTS
  1373. *    day1   - day of the first date
  1374. *    month1 - month of the first date
  1375. *    year1  - year of the first date
  1376. *    day2   - day of the second date
  1377. *    month2 - month of the second month
  1378. *    year2  - year of the second date
  1379. *
  1380. *   RESULT
  1381. *    greater - This is TRUE is date1 > date2 otherwise it's FALSE.
  1382. *
  1383. *   EXAMPLE
  1384. *    ...
  1385. *    if (GregorianDayGreater(18,9,1970,22,1,1994))
  1386. *      printf("<\n");
  1387. *    else
  1388. *      printf(">=\n");
  1389. *    ...
  1390. *
  1391. *   NOTES
  1392. *    It is better only to use this function for years from -7 to 3200!
  1393. *    This function is not longer needed - use CompareDates() !
  1394. *
  1395. *   BUGS
  1396. *    No known bugs.
  1397. *
  1398. *   SEE ALSO
  1399. *    JulianDayGreater(),HeisDayGreater(),CompareDates()
  1400. *
  1401. *****************************************************************************
  1402. *
  1403. *
  1404. */
  1405.  
  1406.  {
  1407.   return((bool)(CompareDates(day1,month1,year1,day2,month2,year2) == 1));
  1408.  }
  1409.  
  1410.  
  1411.  #ifdef __MakeLib
  1412.    bool __saveds __asm HeisDayGreater(register __d0 const unsigned short day1, register __d1 const unsigned short month1, register __d2 const int year1, register __d3 const unsigned short day2, register __d4 const unsigned short month2, register __d5 const int year2)
  1413.  #else
  1414.    bool HeisDayGreater(const unsigned short day1, const unsigned short month1, const int year1, const unsigned short day2, const unsigned short month2, const int year2)
  1415.  #endif
  1416.  
  1417. /*
  1418. *****i* Date/HeisDayGreater *************************************************
  1419. *
  1420. *   NAME
  1421. *    HeisDayGreater -- Checks if date1 is greater than date2. (V33)
  1422. *
  1423. *   SYNOPSIS
  1424. *    greater = HeisDayGreater(day1,month1,year1,day2,month2,year2);
  1425. *      d0              d0    d1    d2    d3    d4    d5
  1426. *
  1427. *    bool HeisDayGreater(const unsigned short day1,
  1428. *        const unsigned short month1, const int year1,
  1429. *        const unsigned short day2, const unsigned short month2,
  1430. *        const int year2);
  1431. *
  1432. *   FUNCTION
  1433. *    HeisDayGreater test if date1 is greater than date2.
  1434. *
  1435. *   INPUTS
  1436. *    day1   - day of the first date
  1437. *    month1 - month of the first date
  1438. *    year1  - year of the first date
  1439. *    day2   - day of the second date
  1440. *    month2 - month of the second month
  1441. *    year2  - year of the second date
  1442. *
  1443. *   RESULT
  1444. *    greater - This is TRUE is date1 > date2 otherwise it's FALSE.
  1445. *
  1446. *   EXAMPLE
  1447. *    ...
  1448. *    if (HeisDayGreater(18,9,1970,22,1,1994))
  1449. *      printf(">\n");
  1450. *    else
  1451. *      printf("<=\n");
  1452. *    ...
  1453. *
  1454. *   NOTES
  1455. *    It is better only to use this function for years from -7 to 8000!
  1456. *    This function is not longer needed - use CompareDates() !
  1457. *
  1458. *   BUGS
  1459. *    No known bugs.
  1460. *
  1461. *   SEE ALSO
  1462. *    JulianDayGreater(),GregorianDayGreater(),CompareDates()
  1463. *
  1464. *****************************************************************************
  1465. *
  1466. *
  1467. */
  1468.  
  1469.  {
  1470.   return((bool)(CompareDates(day1,month1,year1,day2,month2,year2) == 1));
  1471.  }
  1472.  
  1473.  /* ----------------------------------------------------------------------- */
  1474.  
  1475.  #ifdef __MakeLib
  1476.    long __saveds __asm JulianDayDiff(register __d0 const unsigned short day1, register __d1 unsigned short month1, register __d2 int year1, register __d3 const unsigned short day2, register __d4 unsigned short month2, register __d5 int year2)
  1477.  #else
  1478.    long JulianDayDiff(const unsigned short day1, unsigned short month1, int year1, const unsigned short day2, unsigned short month2, int year2)
  1479.  #endif
  1480.  
  1481. /*
  1482. ******* Date/JulianDayDiff **************************************************
  1483. *
  1484. *   NAME
  1485. *    JulianDayDiff -- Calculates the days between 2 dates. (V33)
  1486. *
  1487. *   SYNOPSIS
  1488. *    days = JulianDayDiff(day1,month1,year1,day2,month2,year2);
  1489. *     d0              d0    d1    d2    d3    d4    d5
  1490. *
  1491. *    long JulianDayDiff(const unsigned short day1, unsigned short month1,
  1492. *        int year1, const unsigned short day2, unsigned short month2,
  1493. *        int year2);
  1494. *
  1495. *   FUNCTION
  1496. *    JulianDayDiff gives you back the number of days between
  1497. *    two specified dates.
  1498. *
  1499. *   INPUTS
  1500. *    day1   - day of the first date
  1501. *    month1 - month of the first date
  1502. *    year1  - year of the first date
  1503. *    day2   - day of the second date
  1504. *    month2 - month of the second month
  1505. *    year2  - year of the second date
  1506. *
  1507. *   RESULT
  1508. *    days - The number of days between the two dates
  1509. *        (positive if date1 <= date2).
  1510. *
  1511. *   EXAMPLE
  1512. *    ...
  1513. *    days = JulianDayDiff(18,9,1970,22,1,1994);
  1514. *    printf("Age of Kai Hofmann in days : %d\n",days);
  1515. *    ...
  1516. *
  1517. *   NOTES
  1518. *    It is better only to use this function for years from -7 to 1582!
  1519. *
  1520. *   BUGS
  1521. *    No known bugs.
  1522. *
  1523. *   SEE ALSO
  1524. *    JulianLeapYear(),JulianMonthDays(),JulianYearDays(),
  1525. *    GregorianDayDiff(),HeisDayDiff()
  1526. *
  1527. *****************************************************************************
  1528. *
  1529. *
  1530. */
  1531.  
  1532.  {unsigned long t1,t2;
  1533.  
  1534.   t1 = day1; /* set days left in the actual month */
  1535.   t2 = day2;
  1536.  
  1537.   while (month1 > 1)
  1538.     {/* calc days left by the gone month of the year1 */
  1539.      month1--;
  1540.      t1 += JulianMonthDays(month1,year1);
  1541.     }
  1542.  
  1543.   while (month2 > 1)
  1544.     {/* calc days left by the gone month of the year2 */
  1545.      month2--;
  1546.      t2 += JulianMonthDays(month2,year2);
  1547.     }
  1548.  
  1549.   while (year1 > year2)
  1550.     {/* calc days of diff years */
  1551.      year1--;
  1552.      t1 += JulianYearDays(year1);
  1553.     }
  1554.  
  1555.   while (year1 < year2)
  1556.     {/* calc days of diff years */
  1557.      year2--;
  1558.      t2 += JulianYearDays(year2);
  1559.     }
  1560.  
  1561.   return((long)t2-(long)t1);
  1562.  }
  1563.  
  1564.  
  1565.  #ifdef __MakeLib
  1566.    long __saveds __asm GregorianDayDiff(register __d0 const unsigned short day1, register __d1 unsigned short month1, register __d2 int year1, register __d3 const unsigned short day2, register __d4 unsigned short month2, register __d5 int year2)
  1567.  #else
  1568.    long GregorianDayDiff(const unsigned short day1, unsigned short month1, int year1, const unsigned short day2, unsigned short month2, int year2)
  1569.  #endif
  1570.  
  1571. /*
  1572. ******* Date/GregorianDayDiff ***********************************************
  1573. *
  1574. *   NAME
  1575. *    GregorianDayDiff -- Calculates the days between 2 dates. (V33)
  1576. *
  1577. *   SYNOPSIS
  1578. *    days = GregorianDayDiff(day1,month1,year1,day2,month2,year2);
  1579. *     d0                 d0    d1    d2    d3    d4    d5
  1580. *
  1581. *    long GregorianDayDiff(const unsigned short day1,
  1582. *        unsigned short month1, int year1, const unsigned short day2,
  1583. *        unsigned short month2, int year2);
  1584. *
  1585. *   FUNCTION
  1586. *    GregorianDayDiff gives you back the number of days between
  1587. *    two specified dates.
  1588. *
  1589. *   INPUTS
  1590. *    day1   - day of the first date
  1591. *    month1 - month of the first date
  1592. *    year1  - year of the first date
  1593. *    day2   - day of the second date
  1594. *    month2 - month of the second month
  1595. *    year2  - year of the second date
  1596. *
  1597. *   RESULT
  1598. *    days - The number of days between the two dates
  1599. *        (positive if date1 <= date2).
  1600. *
  1601. *   EXAMPLE
  1602. *    ...
  1603. *    days = GregorianDayDiff(18,9,1970,22,1,1994);
  1604. *    printf("Age of Kai Hofmann in days : %d\n",days);
  1605. *    ...
  1606. *
  1607. *   NOTES
  1608. *    It is better only to use this function for years from -7 to 02.3200!
  1609. *
  1610. *   BUGS
  1611. *    If you use one of the dates 5.10.1582 to 14.10.1582 you will get a
  1612. *    wrong output because these days don't exist!
  1613. *
  1614. *   SEE ALSO
  1615. *    GregorianLeapYear(),GregorianMonthDays(),GregorianYearDays(),
  1616. *    JulianDayDiff(),HeisDayDiff()
  1617. *
  1618. *****************************************************************************
  1619. *
  1620. *
  1621. */
  1622.  
  1623.  {long t1,t2;
  1624.  
  1625.   t1 = day1; /* set days left in the actual month */
  1626.   t2 = day2;
  1627.  
  1628.   if ((year1 == 1582) && (month1 == 10))
  1629.    {if ((day1 < 5) && GregorianDaySmaller(day1,month1,year1,day2,month2,year2) && GregorianDaySmaller(day2,month2,year2,1,11,1582) && GregorianDayGreater(day2,month2,year2,14,10,1582))
  1630.       t2 -= 10;
  1631.     if (day1 > 14)
  1632.      {if (GregorianDaySmaller(day1,month1,year1,day2,month2,year2) && GregorianDayGreater(day2,month2,year2,31,10,1582))
  1633.         t2 += 10;
  1634.       if (GregorianDayGreater(day1,month1,year1,day2,month2,year2) && GregorianDaySmaller(day2,month2,year2,5,10,1582))
  1635.         t1 -= 10;
  1636.      }
  1637.    }
  1638.   if ((year2 == 1582) && (month2 == 10) && (day2 > 14))
  1639.    {if (GregorianDaySmaller(day2,month2,year2,day1,month1,year1) && GregorianDayGreater(day1,month1,year1,31,10,1582))
  1640.       t1 += 10;
  1641.     if (GregorianDayGreater(day2,month2,year2,day1,month1,year1) && GregorianDaySmaller(day1,month1,year1,1,10,1582))
  1642.       t2 -= 10;
  1643.    }
  1644.  
  1645.   while (month1 > 1)
  1646.     {/* calc days left by the gone month of the year1 */
  1647.      month1--;
  1648.      t1 += GregorianMonthDays(month1,year1);
  1649.     }
  1650.  
  1651.   while (month2 > 1)
  1652.     {/* calc days left by the gone month of the year2 */
  1653.      month2--;
  1654.      t2 += GregorianMonthDays(month2,year2);
  1655.     }
  1656.  
  1657.   while (year1 > year2)
  1658.     {/* calc days of diff years */
  1659.      year1--;
  1660.      t1 += GregorianYearDays(year1);
  1661.     }
  1662.  
  1663.   while (year1 < year2)
  1664.     {/* calc days of diff years */
  1665.      year2--;
  1666.      t2 += GregorianYearDays(year2);
  1667.     }
  1668.  
  1669.   return(t2-t1);
  1670.  }
  1671.  
  1672.  
  1673.  #ifdef __MakeLib
  1674.    long __saveds __asm HeisDayDiff(register __d0 const unsigned short day1, register __d1 unsigned short month1, register __d2 int year1, register __d3 const unsigned short day2, register __d4 unsigned short month2, register __d5 int year2)
  1675.  #else
  1676.    long HeisDayDiff(const unsigned short day1, unsigned short month1, int year1, const unsigned short day2, unsigned short month2, int year2)
  1677.  #endif
  1678.  
  1679. /*
  1680. ******* Date/HeisDayDiff ****************************************************
  1681. *
  1682. *   NAME
  1683. *    HeisDayDiff -- Calculates the days between 2 dates. (V33)
  1684. *
  1685. *   SYNOPSIS
  1686. *    days = HeisDayDiff(day1,month1,year1,day2,month2,year2);
  1687. *     d0            d0    d1    d2    d3    d4    d5
  1688. *
  1689. *    long HeisDayDiff(const unsigned short day1, unsigned short month1,
  1690. *        int year1, const unsigned short day2, unsigned short month2,
  1691. *        int year2);
  1692. *
  1693. *   FUNCTION
  1694. *    HeisDayDiff gives you back the number of days between
  1695. *    two specified dates.
  1696. *
  1697. *   INPUTS
  1698. *    day1   - day of the first date
  1699. *    month1 - month of the first date
  1700. *    year1  - year of the first date
  1701. *    day2   - day of the second date
  1702. *    month2 - month of the second month
  1703. *    year2  - year of the second date
  1704. *
  1705. *   RESULT
  1706. *    days - The number of days between the two dates
  1707. *        (positive if date1 <= date2).
  1708. *
  1709. *   EXAMPLE
  1710. *    ...
  1711. *    days = HeisDayDiff(18,9,1970,22,1,1994);
  1712. *    printf("Age of Kai Hofmann in days : %d\n",days);
  1713. *    ...
  1714. *
  1715. *   NOTES
  1716. *    It is better only to use this function for years from -7 to 8000!
  1717. *
  1718. *   BUGS
  1719. *    If you use on of the dates 5.10.1582 to 14.10.1582 you will get
  1720. *    wrong output because these days don't exist!
  1721. *
  1722. *   SEE ALSO
  1723. *    HeisLeapYear(),HeisMonthDays(),HeisYearDays(),
  1724. *    JulianDayDiff(),GregorianDayDiff()
  1725. *
  1726. *****************************************************************************
  1727. *
  1728. *
  1729. */
  1730.  
  1731.  {long t1,t2;
  1732.  
  1733.   t1 = day1; /* set days left in the actual month */
  1734.   t2 = day2;
  1735.  
  1736.   if ((year1 == 1582) && (month1 == 10))
  1737.    {if ((day1 < 5) && HeisDaySmaller(day1,month1,year1,day2,month2,year2) && HeisDaySmaller(day2,month2,year2,1,11,1582) && HeisDayGreater(day2,month2,year2,14,10,1582))
  1738.       t2 -= 10;
  1739.     if (day1 > 14)
  1740.      {if (HeisDaySmaller(day1,month1,year1,day2,month2,year2) && HeisDayGreater(day2,month2,year2,31,10,1582))
  1741.         t2 += 10;
  1742.       if (HeisDayGreater(day1,month1,year1,day2,month2,year2) && HeisDaySmaller(day2,month2,year2,5,10,1582))
  1743.         t1 -= 10;
  1744.      }
  1745.    }
  1746.   if ((year2 == 1582) && (month2 == 10) && (day2 > 14))
  1747.    {if (HeisDaySmaller(day2,month2,year2,day1,month1,year1) && HeisDayGreater(day1,month1,year1,31,10,1582))
  1748.       t1 += 10;
  1749.     if (HeisDayGreater(day2,month2,year2,day1,month1,year1) && HeisDaySmaller(day1,month1,year1,1,10,1582))
  1750.       t2 -= 10;
  1751.    }
  1752.  
  1753.   while (month1 > 1)
  1754.     {/* calc days left by the gone month of the year1 */
  1755.      month1--;
  1756.      t1 += HeisMonthDays(month1,year1);
  1757.     }
  1758.  
  1759.   while (month2 > 1)
  1760.     {/* calc days left by the gone month of the year2 */
  1761.      month2--;
  1762.      t2 += HeisMonthDays(month2,year2);
  1763.     }
  1764.  
  1765.   while (year1 > year2)
  1766.     {/* calc days of diff years */
  1767.      year1--;
  1768.      t1 += HeisYearDays(year1);
  1769.     }
  1770.  
  1771.   while (year1 < year2)
  1772.     {/* calc days of diff years */
  1773.      year2--;
  1774.      t2 += HeisYearDays(year2);
  1775.     }
  1776.  
  1777.   return(t2-t1);
  1778.  }
  1779.  
  1780.  /* ----------------------------------------------------------------------- */
  1781.  
  1782.  #ifdef __MakeLib
  1783.    Weekdays __saveds __asm JulianWeekday(register __d0 const unsigned short day, register __d1 unsigned short month, register __d2 int year)
  1784.  #else
  1785.    Weekdays JulianWeekday(const unsigned short day, unsigned short month, int year)
  1786.  #endif
  1787.  
  1788. /*
  1789. ******* Date/JulianWeekday **************************************************
  1790. *
  1791. *   NAME
  1792. *    JulianWeekday -- Gets the weekday of a specified date. (V33)
  1793. *
  1794. *   SYNOPSIS
  1795. *    weekday = JulianWeekday(day,month,year);
  1796. *      d0             d0   d1   d2
  1797. *
  1798. *    Weekdays JulianWeekday(const unsigned short day,
  1799. *        unsigned short month, int year);
  1800. *
  1801. *   FUNCTION
  1802. *    JulianWeekday gets the weekday for a specified date.
  1803. *
  1804. *   INPUTS
  1805. *    day   - day of the date
  1806. *    month - month of the date
  1807. *    year  - year of the date
  1808. *
  1809. *   RESULT
  1810. *    weekday - This result is of type:
  1811. *        Weekdays = (dayerr,Monday,Tuesday,Wednesday,Thursday,Friday,
  1812. *        Saturday,Sunday);
  1813. *        dayerr will show you, that an error occurs!
  1814. *
  1815. *   EXAMPLE
  1816. *    ...
  1817. *    weekday = JulianWeekday(4,10,1582);
  1818. *    if (weekday == dayerr)
  1819. *      {
  1820. *       ...
  1821. *      }
  1822. *    ...
  1823. *
  1824. *   NOTES
  1825. *    It is better only to use this function for years from 1 to 02.1582!
  1826. *    In this version no dayerr will occur!
  1827. *
  1828. *   BUGS
  1829. *    For years <= 0 errors could occur, or systemcrashs(?).
  1830. *
  1831. *   SEE ALSO
  1832. *    GregorianWeekday(),HeisWeekday()
  1833. *
  1834. *****************************************************************************
  1835. *
  1836. *
  1837. */
  1838.  
  1839.  {unsigned short decade,wday;
  1840.  
  1841.   /* January and february dates must be 13 and 14 of the year before! */
  1842.   switch (month)
  1843.     {case 1 :
  1844.      case 2 : month += 12;
  1845.               year--;
  1846.     }
  1847.   decade = (unsigned short)(year - ((year / 100) * 100));
  1848.   /* Formula from Ch. Zeller in 1877 */
  1849.   wday = (unsigned short)((day + (((month+1) * 26) / 10) + decade +
  1850.             (decade / 4) + 5 - (unsigned short)(year / 100)) % 7);
  1851.   /* Convert (1-su 2-mo 3-tu 4-we 5-th 6-fr 7/0-sa) to normal days */
  1852.   if (wday == 0)
  1853.     wday = 6;
  1854.   else
  1855.     {wday--;
  1856.      if (wday == 0)
  1857.        wday = 7;
  1858.     }
  1859.   return((Weekdays)wday);
  1860.  }
  1861.  
  1862.  
  1863.  #ifdef __MakeLib
  1864.    Weekdays __saveds __asm GregorianWeekday(register __d0 const unsigned short day, register __d1 unsigned short month, register __d2 int year)
  1865.  #else
  1866.    Weekdays GregorianWeekday(const unsigned short day, unsigned short month, int year)
  1867.  #endif
  1868.  
  1869. /*
  1870. ******* Date/GregorianWeekday ***********************************************
  1871. *
  1872. *   NAME
  1873. *    GregorianWeekday -- Gets the weekday of a specified date. (V33)
  1874. *
  1875. *   SYNOPSIS
  1876. *    weekday = GregorianWeekday(day,month,year);
  1877. *      d0                d0   d1   d2
  1878. *
  1879. *    Weekdays GregorianWeekday(const unsigned short day,
  1880. *        unsigned short month, int year);
  1881. *
  1882. *   FUNCTION
  1883. *    GregorianWeekday gets the weekday for a specified date.
  1884. *
  1885. *   INPUTS
  1886. *    day   - day of the date
  1887. *    month - month of the date
  1888. *    year  - year of the date
  1889. *
  1890. *   RESULT
  1891. *    weekday - This result is of type:
  1892. *        Weekdays = (dayerr,Monday,Tuesday,Wednesday,Thursday,Friday,
  1893. *        Saturday,Sunday);
  1894. *        dayerr will show you, that an error occurs!
  1895. *
  1896. *   EXAMPLE
  1897. *    ...
  1898. *    weekday = GregorianWeekday(22,1,1994);
  1899. *    if (weekday == dayerr)
  1900. *      {
  1901. *       ...
  1902. *      }
  1903. *    ...
  1904. *
  1905. *   NOTES
  1906. *    It is better only to use this function for years from -7 to 3200!
  1907. *    In this version dayerr will only occur for the lost days :)
  1908. *
  1909. *   BUGS
  1910. *    It's not possible to use years < 0 (for more see JulianWeekday()).
  1911. *
  1912. *   SEE ALSO
  1913. *    JulianWeekday(),HeisWeekday()
  1914. *
  1915. *****************************************************************************
  1916. *
  1917. *
  1918. */
  1919.  
  1920.  {Weekdays weekday;
  1921.   unsigned int wd;
  1922.  
  1923.   if (GregorianDaySmaller(day,month,year,BeforeGregorianDay+1,BeforeGregorianMonth,BeforeGregorianYear))
  1924.     return(JulianWeekday(day,month,year));
  1925.   else
  1926.     {if (GregorianDaySmaller(day,month,year,AfterGregorianDay,AfterGregorianMonth,AfterGregorianYear))
  1927.        return(dayerr);
  1928.      else
  1929.       {if (year==1582)
  1930.          return((Weekdays)((unsigned short)((GregorianDayDiff(15,10,1582,day,month,year)+4)%7)+1));
  1931.        else
  1932.         {/* Formula from J. I. Perelman 1909 */
  1933.          wd = year + (year / 4) - (year / 100) + (year / 400)
  1934.                 + (int)GregorianDayDiff(1,1,year,day,month,year);
  1935.          if (GregorianLeapYear(year))
  1936.            wd--;
  1937.          weekday = (Weekdays)(wd % 7);
  1938.          if (weekday == dayerr)
  1939.            weekday = Sunday;
  1940.          return(weekday);
  1941.         }
  1942.       }
  1943.     }
  1944.  }
  1945.  
  1946.  
  1947.  #ifdef __MakeLib
  1948.    Weekdays __saveds __asm HeisWeekday(register __d0 const unsigned short day, register __d1 unsigned short month, register __d2 int year)
  1949.  #else
  1950.    Weekdays HeisWeekday(const unsigned short day, unsigned short month, int year)
  1951.  #endif
  1952.  
  1953. /*
  1954. ******* Date/HeisWeekday ****************************************************
  1955. *
  1956. *   NAME
  1957. *    HeisWeekday -- Gets the weekday of a specified date. (V33)
  1958. *
  1959. *   SYNOPSIS
  1960. *    weekday = HeisWeekday(day,month,year);
  1961. *      d0               d0   d1   d2
  1962. *
  1963. *    Weekdays HeisWeekday(const unsigned short day, unsigned short month,
  1964. *        int year);
  1965. *
  1966. *   FUNCTION
  1967. *    HeisWeekday gets the weekday for a specified date.
  1968. *
  1969. *   INPUTS
  1970. *    day   - day of the date
  1971. *    month - month of the date
  1972. *    year  - year of the date
  1973. *
  1974. *   RESULT
  1975. *    weekday - This result is of type:
  1976. *        Weekdays = (dayerr,Monday,Tuesday,Wednesday,Thursday,Friday,
  1977. *        Saturday,Sunday);
  1978. *        dayerr will show you, that an error occurs!
  1979. *
  1980. *   EXAMPLE
  1981. *    ...
  1982. *    weekday = HeisWeekday(22,1,1994);
  1983. *    if (weekday == dayerr)
  1984. *      {
  1985. *       ...
  1986. *      }
  1987. *    ...
  1988. *
  1989. *   NOTES
  1990. *    It is better only to use this function for years from -7 to 8000!
  1991. *    In this version dayerr will only occur for the lost days :)
  1992. *
  1993. *   BUGS
  1994. *    It is not possible to use year < 0 (see JulianWeekday() for more).
  1995. *
  1996. *   SEE ALSO
  1997. *    JulianWeekday(),GregorianWeekday()
  1998. *
  1999. *****************************************************************************
  2000. *
  2001. *
  2002. */
  2003.  
  2004.  {Weekdays weekday;
  2005.   unsigned int wd;
  2006.  
  2007.   if (HeisDaySmaller(day,month,year,StartHeisDay,StartHeisMonth,StartHeisYear))
  2008.     return(GregorianWeekday(day,month,year));
  2009.   else
  2010.     {/* Formula from J. I. Perelman 1909 - extended for N.Heis in 01.1994
  2011.     by Kai Hofmann */
  2012.      wd = year + (year / 4) - (year / 100) + (year / 400)
  2013.         - (year / 3200) + (int)HeisDayDiff(1,1,year,day,month,year);
  2014.      if (HeisLeapYear(year))
  2015.        wd--;
  2016.      weekday = (Weekdays)(wd % 7);
  2017.      if (weekday == dayerr)
  2018.        weekday = Sunday;
  2019.      return(weekday);
  2020.     }
  2021.  }
  2022.  
  2023.  /* ----------------------------------------------------------------------- */
  2024.  
  2025.  #ifdef __MakeLib
  2026.    unsigned short __saveds __asm JulianDaysBeforeWeekday(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year, register __d3 const Weekdays weekday)
  2027.  #else
  2028.    unsigned short JulianDaysBeforeWeekday(const unsigned short day, const unsigned short month, const int year, const Weekdays weekday)
  2029.  #endif
  2030.  
  2031. /*
  2032. ******* Date/JulianDaysBeforeWeekday ****************************************
  2033. *
  2034. *   NAME
  2035. *    JulianDaysBeforeWeekday -- Returns the diff to the wday before. (V33)
  2036. *
  2037. *   SYNOPSIS
  2038. *    days = JulianDaysBeforeWeekday(day,month,year,weekday);
  2039. *     d0                d0  d1    d2    d3
  2040. *
  2041. *    unsigned short JulianDaysBeforeWeekday(const unsigned short day,
  2042. *        const unsigned short month, const int year,
  2043. *        const Weekdays weekday);
  2044. *
  2045. *   FUNCTION
  2046. *    Returns the days to the weekday before the specified date.
  2047. *    So if you specify the 22.1.1994 (Saturday) and Thursday
  2048. *    you get back 2!
  2049. *    If you specify the 22.1.1994 and Saturday you get back 0
  2050. *    (the same day)!
  2051. *
  2052. *   INPUTS
  2053. *    day     - day of the date
  2054. *    month   - month of the date
  2055. *    year    - year of the date
  2056. *    weekday - weekday to search for building difference
  2057. *
  2058. *   RESULT
  2059. *    days - The days back to the searched weekday (0-6)
  2060. *        If you get back 8 an error occurs!
  2061. *
  2062. *   EXAMPLE
  2063. *    ...
  2064. *    days = JulianDaysBeforeWeekday(22,1,1994,Thursday);
  2065. *    ...
  2066. *
  2067. *   NOTES
  2068. *    It is better to use this function only from -7 to 02.1582!
  2069. *
  2070. *   BUGS
  2071. *    See JulianWeekday()!
  2072. *
  2073. *   SEE ALSO
  2074. *    JulianWeekday(),GregorianDaysBeforeWeekday(),HeisDaysBeforeWeekday()
  2075. *
  2076. *****************************************************************************
  2077. *
  2078. *
  2079. */
  2080.  
  2081.  {Weekdays wday;
  2082.  
  2083.   if (weekday == dayerr)
  2084.     return(8);
  2085.   else
  2086.     {wday = JulianWeekday(day,month,year);
  2087.      if (wday >= weekday)
  2088.        return((unsigned short)(wday-weekday));
  2089.      else
  2090.        {/* wday < weekday */
  2091.         return((unsigned short)(7-weekday+wday));
  2092.        }
  2093.     }
  2094.  }
  2095.  
  2096.  
  2097.  #ifdef __MakeLib
  2098.    unsigned short __saveds __asm GregorianDaysBeforeWeekday(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year, register __d3 const Weekdays weekday)
  2099.  #else
  2100.    unsigned short GregorianDaysBeforeWeekday(const unsigned short day, const unsigned short month, const int year, const Weekdays weekday)
  2101.  #endif
  2102.  
  2103. /*
  2104. ******* Date/GregorianDaysBeforeWeekday *************************************
  2105. *
  2106. *   NAME
  2107. *    GregorianDaysBeforeWeekday -- Returns the diff to wday before. (V33)
  2108. *
  2109. *   SYNOPSIS
  2110. *    days = GregorianDaysBeforeWeekday(day,month,year,weekday);
  2111. *     d0                   d0  d1    d2    d3
  2112. *
  2113. *    unsigned short GregorianDaysBeforeWeekday(const unsigned short day,
  2114. *        const unsigned short month, const int year,
  2115. *        const Weekdays weekday);
  2116. *
  2117. *   FUNCTION
  2118. *    Returns the days to the weekday before the specified date.
  2119. *    So if you specify the 22.1.1994 (Saturday) and Thursday
  2120. *    you get back 2!
  2121. *    If you specify the 22.1.1994 and Saturday you get back 0
  2122. *    (the same day)!
  2123. *
  2124. *   INPUTS
  2125. *    day     - day of the date
  2126. *    month   - month of the date
  2127. *    year    - year of the date
  2128. *    weekday - weekday to search for building difference
  2129. *
  2130. *   RESULT
  2131. *    days - The days back to the searched weekday (1-7)
  2132. *        If you get back 8 an error occurs!
  2133. *
  2134. *   EXAMPLE
  2135. *    ...
  2136. *    days = GregorianDaysBeforeWeekday(22,1,1994,Thursday);
  2137. *    ...
  2138. *
  2139. *   NOTES
  2140. *    It is better to use this function only from -7 to 3200!
  2141. *
  2142. *   BUGS
  2143. *    See GregorianWeekday()!
  2144. *
  2145. *   SEE ALSO
  2146. *    GregorianWeekday(),JulianDaysBeforeWeekday(),HeisDaysBeforeWeekday()
  2147. *
  2148. *****************************************************************************
  2149. *
  2150. *
  2151. */
  2152.  
  2153.  {Weekdays wday;
  2154.  
  2155.   if (weekday == dayerr)
  2156.     return(8);
  2157.   else
  2158.     {wday = GregorianWeekday(day,month,year);
  2159.      if (wday >= weekday)
  2160.        return((unsigned short)(wday-weekday));
  2161.      else
  2162.        {/* wday < weekday */
  2163.         return((unsigned short)(7-weekday+wday));
  2164.        }
  2165.     }
  2166.  }
  2167.  
  2168.  
  2169.  #ifdef __MakeLib
  2170.    unsigned short __saveds __asm HeisDaysBeforeWeekday(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year, register __d3 const Weekdays weekday)
  2171.  #else
  2172.    unsigned short HeisDaysBeforeWeekday(const unsigned short day, const unsigned short month, const int year, const Weekdays weekday)
  2173.  #endif
  2174.  
  2175. /*
  2176. ******* Date/HeisDaysBeforeWeekday ******************************************
  2177. *
  2178. *   NAME
  2179. *    HeisDaysBeforeWeekday -- Returns the diff to wday before. (V33)
  2180. *
  2181. *   SYNOPSIS
  2182. *    days = HeisDaysBeforeWeekday(day,month,year,weekday);
  2183. *     d0                  d0  d1    d2    d3
  2184. *
  2185. *    unsigned short HeisDaysBeforeWeekday(const unsigned short day,
  2186. *        const unsigned short month, const int year,
  2187. *        const Weekdays weekday);
  2188. *
  2189. *   FUNCTION
  2190. *    Returns the days to the weekday before the specified date.
  2191. *    So if you specify the 22.1.1994 (Saturday) and Thursday
  2192. *    you get back 2!
  2193. *    If you specify the 22.1.1994 and Saturday you get back 0
  2194. *    (the same day)!
  2195. *
  2196. *   INPUTS
  2197. *    day     - day of the date
  2198. *    month   - month of the date
  2199. *    year    - year of the date
  2200. *    weekday - weekday to search for building difference
  2201. *
  2202. *   RESULT
  2203. *    days - The days back to the searched weekday (1-7)
  2204. *        If you get back 8 an error occurs!
  2205. *
  2206. *   EXAMPLE
  2207. *    ...
  2208. *    days = HeisDaysBeforeWeekday(22,1,1994,Thursday);
  2209. *    ...
  2210. *
  2211. *   NOTES
  2212. *    It is better to use this function only from -7 to 8000!
  2213. *
  2214. *   BUGS
  2215. *    See HeisWeekday()!
  2216. *
  2217. *   SEE ALSO
  2218. *    HeisWeekday(),JulianDaysBeforeWeekday(),GregorianDaysBeforeWeekday()
  2219. *
  2220. *****************************************************************************
  2221. *
  2222. *
  2223. */
  2224.  
  2225.  {Weekdays wday;
  2226.  
  2227.   if (weekday == dayerr)
  2228.     return(8);
  2229.   else
  2230.     {wday = HeisWeekday(day,month,year);
  2231.      if (wday >= weekday)
  2232.        return((unsigned short)(wday-weekday));
  2233.      else
  2234.        {/* wday < weekday */
  2235.         return((unsigned short)(7-weekday+wday));
  2236.        }
  2237.     }
  2238.  }
  2239.  
  2240.  /* ----------------------------------------------------------------------- */
  2241.  
  2242.  #ifdef __MakeLib
  2243.    unsigned short __saveds __asm JulianDaysAfterWeekday(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year, register __d3 const Weekdays weekday)
  2244.  #else
  2245.    unsigned short JulianDaysAfterWeekday(const unsigned short day, const unsigned short month, const int year, const Weekdays weekday)
  2246.  #endif
  2247.  
  2248. /*
  2249. ******* Date/JulianDaysAfterWeekday *****************************************
  2250. *
  2251. *   NAME
  2252. *    JulianDaysAfterWeekday -- Returns the diff to the wday after. (V33)
  2253. *
  2254. *   SYNOPSIS
  2255. *    days = JulianDaysAfterWeekday(day,month,year,weekday);
  2256. *     d0                   d0   d1   d2     d3
  2257. *
  2258. *    unsigned short JulianDaysAfterWeekday(const unsigned short day,
  2259. *        const unsigned short month, const int year,
  2260. *        const Weekdays weekday);
  2261. *
  2262. *   FUNCTION
  2263. *    Returns the days to the weekday after the specified date.
  2264. *    So if you specify the 22.1.1994 (Saturday) and Thursday
  2265. *    you get back 5!
  2266. *    If you specify the 22.1.1994 and Saturday you get back 0
  2267. *    (the same day)!
  2268. *
  2269. *   INPUTS
  2270. *    day     - day of the date
  2271. *    month   - month of the date
  2272. *    year    - year of the date
  2273. *    weekday - weekday to search for building difference
  2274. *
  2275. *   RESULT
  2276. *    days - The days after to the searched weekday.
  2277. *
  2278. *   EXAMPLE
  2279. *    ...
  2280. *    days = JulianDaysAfterWeekday(22,1,1994,Thursday);
  2281. *    ...
  2282. *
  2283. *   NOTES
  2284. *    It is better to use this function only from -7 to 1582!
  2285. *
  2286. *   BUGS
  2287. *    See JulianWeekday()!
  2288. *
  2289. *   SEE ALSO
  2290. *    JulianWeekday(),GregorianDaysAfterWeekday(),HeisDaysAfterWeekday()
  2291. *
  2292. *****************************************************************************
  2293. *
  2294. *
  2295. */
  2296.  
  2297.  {Weekdays wday;
  2298.  
  2299.   if (weekday == dayerr)
  2300.     return(8);
  2301.   else
  2302.     {wday = JulianWeekday(day,month,year);
  2303.      if (wday <= weekday)
  2304.        return((unsigned short)(weekday-wday));
  2305.      else
  2306.        {/* wday > weekday */
  2307.         return((unsigned short)(7-wday+weekday));
  2308.        }
  2309.     }
  2310.  }
  2311.  
  2312.  
  2313.  #ifdef __MakeLib
  2314.    unsigned short __saveds __asm GregorianDaysAfterWeekday(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year, register __d3 const Weekdays weekday)
  2315.  #else
  2316.    unsigned short GregorianDaysAfterWeekday(const unsigned short day, const unsigned short month, const int year, const Weekdays weekday)
  2317.  #endif
  2318.  
  2319. /*
  2320. ******* Date/GregorianDaysAfterWeekday **************************************
  2321. *
  2322. *   NAME
  2323. *    GregorianDaysAfterWeekday -- Returns the diff to wday after. (V33)
  2324. *
  2325. *   SYNOPSIS
  2326. *    days = GregorianDaysAfterWeekday(day,month,year,weekday);
  2327. *     d0                      d0   d1   d2     d3
  2328. *
  2329. *    unsigned short GregorianDaysAfterWeekday(const unsigned short day,
  2330. *        const unsigned short month, const int year,
  2331. *        const Weekdays weekday);
  2332. *
  2333. *   FUNCTION
  2334. *    Returns the days to the weekday after the specified date.
  2335. *    So if you specify the 22.1.1994 (Saturday) and Thursday
  2336. *    you get back 5!
  2337. *    If you specify the 22.1.1994 and Saturday you get back 0
  2338. *    (the same day)!
  2339. *
  2340. *   INPUTS
  2341. *    day     - day of the date
  2342. *    month   - month of the date
  2343. *    year    - year of the date
  2344. *    weekday - weekday to search for building difference
  2345. *
  2346. *   RESULT
  2347. *    days - The days after to the searched weekday.
  2348. *
  2349. *   EXAMPLE
  2350. *    ...
  2351. *    days = GregorianDaysAfterWeekday(22,1,1994,Thursday);
  2352. *    ...
  2353. *
  2354. *   NOTES
  2355. *    It is better to use this function only from -7 to 3200!
  2356. *
  2357. *   BUGS
  2358. *    See GregorianWeekday()!
  2359. *
  2360. *   SEE ALSO
  2361. *    GregorianWeekday(),JulianDaysAfterWeekday(),HeisDaysAfterWeekday()
  2362. *
  2363. *****************************************************************************
  2364. *
  2365. *
  2366. */
  2367.  
  2368.  {Weekdays wday;
  2369.  
  2370.   if (weekday == dayerr)
  2371.     return(8);
  2372.   else
  2373.     {wday = GregorianWeekday(day,month,year);
  2374.      if (wday <= weekday)
  2375.        return((unsigned short)(weekday-wday));
  2376.      else
  2377.        {/* wday > weekday */
  2378.         return((unsigned short)(7-wday+weekday));
  2379.        }
  2380.     }
  2381.  }
  2382.  
  2383.  
  2384.  #ifdef __MakeLib
  2385.    unsigned short __saveds __asm HeisDaysAfterWeekday(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year, register __d3 const Weekdays weekday)
  2386.  #else
  2387.    unsigned short HeisDaysAfterWeekday(const unsigned short day, const unsigned short month, const int year, const Weekdays weekday)
  2388.  #endif
  2389.  
  2390. /*
  2391. ******* Date/HeisDaysAfterWeekday *******************************************
  2392. *
  2393. *   NAME
  2394. *    HeisDaysAfterWeekday -- Returns the diff to the wday after. (V33)
  2395. *
  2396. *   SYNOPSIS
  2397. *    days = HeisDaysAfterWeekday(day,month,year,weekday);
  2398. *     d0                 d0   d1   d2     d3
  2399. *
  2400. *    unsigned short HeisDaysAfterWeekday(const unsigned short day,
  2401. *        const unsigned short month, const int year,
  2402. *        const Weekdays weekday);
  2403. *
  2404. *   FUNCTION
  2405. *    Returns the days to the weekday after the specified date.
  2406. *    So if you specify the 22.1.1994 (Saturday) and Thursday
  2407. *    you get back 5!
  2408. *    If you specify the 22.1.1994 and Saturday you get back 0
  2409. *    (the same day)!
  2410. *
  2411. *   INPUTS
  2412. *    day     - day of the date
  2413. *    month   - month of the date
  2414. *    year    - year of the date
  2415. *    weekday - weekday to search for building difference
  2416. *
  2417. *   RESULT
  2418. *    days - The days after to the searched weekday.
  2419. *
  2420. *   EXAMPLE
  2421. *    ...
  2422. *    days = HeisDaysAfterWeekday(22,1,1994,Thursday);
  2423. *    ...
  2424. *
  2425. *   NOTES
  2426. *    It is better to use this function only from -7 to 8000!
  2427. *
  2428. *   BUGS
  2429. *    See HeisWeekday()!
  2430. *
  2431. *   SEE ALSO
  2432. *    HeisWeekday(),JulianDaysAfterWeekday(),GregorianDaysAfterWeekday()
  2433. *
  2434. *****************************************************************************
  2435. *
  2436. *
  2437. */
  2438.  
  2439.  {Weekdays wday;
  2440.  
  2441.   if (weekday == dayerr)
  2442.     return(8);
  2443.   else
  2444.     {wday = HeisWeekday(day,month,year);
  2445.      if (wday <= weekday)
  2446.        return((unsigned short)(weekday-wday));
  2447.      else
  2448.        {/* wday > weekday */
  2449.         return((unsigned short)(7-wday+weekday));
  2450.        }
  2451.     }
  2452.  }
  2453.  
  2454.  /* ----------------------------------------------------------------------- */
  2455.  
  2456.  #ifdef __MakeLib
  2457.    void __saveds __asm JulianDiffDate(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year, register __d3 int days, register __a0 unsigned short *dday, register __a1 unsigned short *dmonth, register __a2 int *dyear)
  2458.  #else
  2459.    void JulianDiffDate(const unsigned short day, const unsigned short month, const int year, int days, unsigned short *dday, unsigned short *dmonth, int *dyear)
  2460.  #endif
  2461.  
  2462. /*
  2463. ******* Date/JulianDiffDate *************************************************
  2464. *
  2465. *   NAME
  2466. *    JulianDiffDate -- Returns the date for a diff to another date. (V33)
  2467. *
  2468. *   SYNOPSIS
  2469. *    JulianDiffDate(day,month,year,diffdays,dday,dmonth,dyear);
  2470. *            d0   d1   d2     d3     a0    a1    a2
  2471. *
  2472. *    void JulianDiffDate(const unsigned short day,
  2473. *        const unsigned short month, const int year, int days,
  2474. *        unsigned short *dday, unsigned short *dmonth, int *dyear);
  2475. *
  2476. *   FUNCTION
  2477. *    Returns the date which lies diffdays before/after the specified date.
  2478. *
  2479. *   INPUTS
  2480. *    day      - day of the date
  2481. *    month    - month of the date
  2482. *    year     - year of the date
  2483. *    diffdays - difference to the date in days
  2484. *
  2485. *   RESULT
  2486. *    dday   - Destination day
  2487. *    dmonth - Destination month
  2488. *    dyear  - Destination year
  2489. *
  2490. *   EXAMPLE
  2491. *    ...
  2492. *    JulianDiffDate(23,1,1994,7,&dday,&dmonth,&dyear);
  2493. *    ...
  2494. *
  2495. *   NOTES
  2496. *    It is better to use this function only from -7 to 1582!
  2497. *
  2498. *   BUGS
  2499. *    unknown.
  2500. *
  2501. *   SEE ALSO
  2502. *    JulianDayDiff(),JulianMonthDays(),GregorianDiffDate(),HeisDiffDate()
  2503. *
  2504. *****************************************************************************
  2505. *
  2506. *
  2507. */
  2508.  
  2509.  {int ddays;
  2510.  
  2511.   *dday = day;
  2512.   *dmonth = month;
  2513.   *dyear = year;
  2514.   if (days >= 0)
  2515.     {/* add */
  2516.      ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,1,1,(*dyear)+1);
  2517.      while (days >= ddays)
  2518.        {/* years */
  2519.         *dday = 1;
  2520.         *dmonth = 1;
  2521.         (*dyear)++;
  2522.         days -= ddays;
  2523.         ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,1,1,(*dyear)+1);
  2524.        }
  2525.      ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,1,(*dmonth)+1,*dyear);
  2526.      while (days >= ddays)
  2527.        {/* months */
  2528.         *dday = 1;
  2529.         (*dmonth)++;
  2530.         days -= ddays;
  2531.         ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,1,(*dmonth)+1,*dyear);
  2532.        }
  2533.      if (days > 0)
  2534.        {/* days */
  2535.         *dday += (unsigned short)days;
  2536.        }
  2537.     }
  2538.   else
  2539.     {/* sub */
  2540.      ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,31,12,(*dyear)-1);
  2541.      while (days <= ddays)
  2542.        {/* years */
  2543.         *dday = 31;
  2544.         *dmonth = 12;
  2545.         (*dyear)--;
  2546.         days -= ddays;
  2547.         ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,31,12,(*dyear)-1);
  2548.        }
  2549.      ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,JulianMonthDays((*dmonth)-1,*dyear),(*dmonth)-1,*dyear);
  2550.      while (days <= ddays)
  2551.        {/* months */
  2552.         *dday = JulianMonthDays((*dmonth)-1,*dyear);
  2553.         (*dmonth)--;
  2554.         days -= ddays;
  2555.         ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,JulianMonthDays((*dmonth)-1,*dyear),(*dmonth)-1,*dyear);
  2556.        }
  2557.      if (days < 0)
  2558.        *dday -= (unsigned short)abs(days);
  2559.     }
  2560.  }
  2561.  
  2562.  
  2563.  #ifdef __MakeLib
  2564.    void __saveds __asm GregorianDiffDate(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year, register __d3 int days, register __a0 unsigned short *dday, register __a1 unsigned short *dmonth, register __a2 int *dyear)
  2565.  #else
  2566.    void GregorianDiffDate(const unsigned short day, const unsigned short month, const int year, int days, unsigned short *dday, unsigned short *dmonth, int *dyear)
  2567.  #endif
  2568.  
  2569. /*
  2570. ******* Date/GregorianDiffDate **********************************************
  2571. *
  2572. *   NAME
  2573. *    GregorianDiffDate -- Returns the diff date to another date. (V33)
  2574. *
  2575. *   SYNOPSIS
  2576. *    GregorianDiffDate(day,month,year,diffdays,dday,dmonth,dyear);
  2577. *               d0   d1   d2     d3     a0    a1    a2
  2578. *
  2579. *    void GregorianDiffDate(const unsigned short day,
  2580. *        const unsigned short month, const int year, int days,
  2581. *        unsigned short *dday, unsigned short *dmonth, int *dyear);
  2582. *
  2583. *   FUNCTION
  2584. *    Returns the date which lies diffdays before/after the specified date.
  2585. *
  2586. *   INPUTS
  2587. *    day      - day of the date
  2588. *    month    - month of the date
  2589. *    year     - year of the date
  2590. *    diffdays - difference to the date in days
  2591. *
  2592. *   RESULT
  2593. *    dday   - Destination day
  2594. *    dmonth - Destination month
  2595. *    dyear  - Destination year
  2596. *
  2597. *   EXAMPLE
  2598. *    ...
  2599. *    GregorianDiffDate(23,1,1994,7,&dday,&dmonth,&dyear);
  2600. *    ...
  2601. *
  2602. *   NOTES
  2603. *    It is better to use this function only from -7 to 3200!
  2604. *
  2605. *   BUGS
  2606. *    unknown.
  2607. *
  2608. *   SEE ALSO
  2609. *    GregorianDayDiff(),GregorianMonthDays(),JulianDiffDate(),
  2610. *    HeisDiffDate()
  2611. *
  2612. *****************************************************************************
  2613. *
  2614. *
  2615. */
  2616.  
  2617.  {int ddays;
  2618.  
  2619.   *dday = day;
  2620.   *dmonth = month;
  2621.   *dyear = year;
  2622.   if (days >= 0)
  2623.     {/* add */
  2624.      ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,1,1,(*dyear)+1);
  2625.      while (days >= ddays)
  2626.        {/* years */
  2627.         *dday = 1;
  2628.         *dmonth = 1;
  2629.         (*dyear)++;
  2630.         days -= ddays;
  2631.         ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,1,1,(*dyear)+1);
  2632.        }
  2633.      ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,1,(*dmonth)+1,*dyear);
  2634.      while (days >= ddays)
  2635.        {/* months */
  2636.         *dday = 1;
  2637.         (*dmonth)++;
  2638.         days -= ddays;
  2639.         ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,1,(*dmonth)+1,*dyear);
  2640.        }
  2641.      if (days > 0)
  2642.        {/* days */
  2643.         *dday += (unsigned short)days;
  2644.        }
  2645.     }
  2646.   else
  2647.     {/* sub */
  2648.      ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,31,12,(*dyear)-1);
  2649.      while (days <= ddays)
  2650.        {/* years */
  2651.         *dday = 31;
  2652.         *dmonth = 12;
  2653.         (*dyear)--;
  2654.         days -= ddays;
  2655.         ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,31,12,(*dyear)-1);
  2656.        }
  2657.      ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,GregorianMonthDays((*dmonth)-1,*dyear),(*dmonth-1),*dyear);
  2658.      while (days <= ddays)
  2659.        {/* months */
  2660.         *dday = GregorianMonthDays((*dmonth-1),*dyear);
  2661.         (*dmonth)--;
  2662.         days -= ddays;
  2663.         ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,GregorianMonthDays((*dmonth)-1,*dyear),(*dmonth)-1,*dyear);
  2664.        }
  2665.      if (days < 0)
  2666.        *dday -= (unsigned short)abs(days);
  2667.     }
  2668.  }
  2669.  
  2670.  
  2671.  #ifdef __MakeLib
  2672.    void __saveds __asm HeisDiffDate(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year, register __d3 int days, register __a0 unsigned short *dday, register __a1 unsigned short *dmonth, register __a2 int *dyear)
  2673.  #else
  2674.    void HeisDiffDate(const unsigned short day, const unsigned short month, const int year, int days, unsigned short *dday, unsigned short *dmonth, int *dyear)
  2675.  #endif
  2676.  
  2677. /*
  2678. ******* Date/HeisDiffDate ***************************************************
  2679. *
  2680. *   NAME
  2681. *    HeisDiffDate -- Returns the date for a diff to another date. (V33)
  2682. *
  2683. *   SYNOPSIS
  2684. *    HeisDiffDate(day,month,year,diffdays,dday,dmonth,dyear);
  2685. *              d0   d1   d2     d3     a0    a1    a2
  2686. *
  2687. *    void HeisDiffDate(const unsigned short day,
  2688. *        const unsigned short month, const int year, int days,
  2689. *        unsigned short *dday, unsigned short *dmonth, int *dyear);
  2690. *
  2691. *   FUNCTION
  2692. *    Returns the date which lies diffdays before/after the specified date.
  2693. *
  2694. *   INPUTS
  2695. *    day      - day of the date
  2696. *    month    - month of the date
  2697. *    year     - year of the date
  2698. *    diffdays - difference to the date in days
  2699. *
  2700. *   RESULT
  2701. *    dday   - Destination day
  2702. *    dmonth - Destination month
  2703. *    dyear  - Destination year
  2704. *
  2705. *   EXAMPLE
  2706. *    ...
  2707. *    HeisDiffDate(23,1,1994,7,&dday,&dmonth,&dyear);
  2708. *    ...
  2709. *
  2710. *   NOTES
  2711. *    It is better to use this function only from -7 to 8000!
  2712. *
  2713. *   BUGS
  2714. *    unknown.
  2715. *
  2716. *   SEE ALSO
  2717. *    HeisDayDiff(),HeisMonthDays(),JulianDiffDate(),GregorianDiffDate()
  2718. *
  2719. *****************************************************************************
  2720. *
  2721. *
  2722. */
  2723.  
  2724.  {int ddays;
  2725.  
  2726.   *dday = day;
  2727.   *dmonth = month;
  2728.   *dyear = year;
  2729.   if (days >= 0)
  2730.     {/* add */
  2731.      ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,1,1,(*dyear)+1);
  2732.      while (days >= ddays)
  2733.        {/* years */
  2734.         *dday = 1;
  2735.         *dmonth = 1;
  2736.         (*dyear)++;
  2737.         days -= ddays;
  2738.         ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,1,1,(*dyear)+1);
  2739.        }
  2740.      ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,1,(*dmonth+1),*dyear);
  2741.      while (days >= ddays)
  2742.        {/* months */
  2743.         *dday = 1;
  2744.         (*dmonth)++;
  2745.         days -= ddays;
  2746.         ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,1,(*dmonth)+1,*dyear);
  2747.        }
  2748.      if (days > 0)
  2749.        {/* days */
  2750.         *dday += (unsigned short)days;
  2751.        }
  2752.     }
  2753.   else
  2754.     {/* sub */
  2755.      ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,31,12,(*dyear)-1);
  2756.      while (days <= ddays)
  2757.        {/* years */
  2758.         *dday = 31;
  2759.         *dmonth = 12;
  2760.         (*dyear)--;
  2761.         days -= ddays;
  2762.         ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,31,12,(*dyear)-1);
  2763.        }
  2764.      ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,HeisMonthDays((*dmonth)-1,*dyear),(*dmonth)-1,*dyear);
  2765.      while (days <= ddays)
  2766.        {/* months */
  2767.         *dday = HeisMonthDays((*dmonth)-1,*dyear);
  2768.         (*dmonth)--;
  2769.         days -= ddays;
  2770.         ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,HeisMonthDays((*dmonth)-1,*dyear),(*dmonth)-1,*dyear);
  2771.        }
  2772.      if (days < 0)
  2773.        *dday -= (unsigned short)abs(days);
  2774.     }
  2775.  }
  2776.  
  2777.  /* ----------------------------------------------------------------------- */
  2778.  
  2779.  #ifdef __MakeLib
  2780.    unsigned int __saveds __asm JYearToScaliger(register __d0 const int year)
  2781.  #else
  2782.    unsigned int JYearToScaliger(const int year)
  2783.  #endif
  2784.  
  2785. /*
  2786. ******* Date/JYearToScaliger ************************************************
  2787. *
  2788. *   NAME
  2789. *    JYearToScaliger -- Returns the year as Scaliger year. (V33)
  2790. *
  2791. *   SYNOPSIS
  2792. *    syear = JYearToScaliger(year);
  2793. *     d0             d0
  2794. *
  2795. *    unsigned int JYearToScaliger(const int year);
  2796. *
  2797. *   FUNCTION
  2798. *    Returns the Scaliger year.
  2799. *
  2800. *   INPUTS
  2801. *    year     - Julian year
  2802. *
  2803. *   RESULT
  2804. *    syear - The Scaliger year
  2805. *
  2806. *   EXAMPLE
  2807. *    ...
  2808. *    syear = JYearToScaliger(1582);
  2809. *    ...
  2810. *
  2811. *   NOTES
  2812. *    It is better to use this function only from -7 to 1582!
  2813. *
  2814. *   BUGS
  2815. *    unknown.
  2816. *
  2817. *   SEE ALSO
  2818. *    GYearToScaliger(),HYearToScaliger()
  2819. *
  2820. *****************************************************************************
  2821. *
  2822. *
  2823. */
  2824.  
  2825.  {if ((year < 0) && (year > -4714))
  2826.     return((unsigned int)(4714+year));
  2827.   else
  2828.     if ((year > 0) && (year < 3268))
  2829.       return((unsigned int)(4713+year));
  2830.     else
  2831.       return(0);
  2832.  }
  2833.  
  2834.  
  2835.  #ifdef __MakeLib
  2836.    unsigned int __saveds __asm GYearToScaliger(register __d0 const int year)
  2837.  #else
  2838.    unsigned int GYearToScaliger(const int year)
  2839.  #endif
  2840.  
  2841. /*
  2842. ******* Date/GYearToScaliger ************************************************
  2843. *
  2844. *   NAME
  2845. *    GYearToScaliger -- Returns the year as Scaliger year. (V33)
  2846. *
  2847. *   SYNOPSIS
  2848. *    syear = GYearToScaliger(year);
  2849. *     d0             d0
  2850. *
  2851. *    unsigned int GYearToScaliger(const int year);
  2852. *
  2853. *   FUNCTION
  2854. *    Returns the Scaliger year.
  2855. *
  2856. *   INPUTS
  2857. *    year     - Gregorian year
  2858. *
  2859. *   RESULT
  2860. *    syear - The Scaliger year
  2861. *
  2862. *   EXAMPLE
  2863. *    ...
  2864. *    syear = GYearToScaliger(1994);
  2865. *    ...
  2866. *
  2867. *   NOTES
  2868. *    It is better to use this function only from -7 to 3200!
  2869. *
  2870. *   BUGS
  2871. *    unknown.
  2872. *
  2873. *   SEE ALSO
  2874. *    JYearToScaliger(),HYearToScaliger()
  2875. *
  2876. *****************************************************************************
  2877. *
  2878. *
  2879. */
  2880.  
  2881.  {/* if other calcs are better use here! */
  2882.   return(JYearToScaliger(year));
  2883.  }
  2884.  
  2885.  
  2886.  #ifdef __MakeLib
  2887.    unsigned int __saveds __asm HYearToScaliger(register __d0 const int year)
  2888.  #else
  2889.    unsigned int HYearToScaliger(const int year)
  2890.  #endif
  2891.  
  2892. /*
  2893. ******* Date/HYearToScaliger ************************************************
  2894. *
  2895. *   NAME
  2896. *    HYearToScaliger -- Returns the year as Scaliger year. (V33)
  2897. *
  2898. *   SYNOPSIS
  2899. *    syear = HYearToScaliger(year);
  2900. *     d0             d0
  2901. *
  2902. *    unsigned int HYearToScaliger(const int year);
  2903. *
  2904. *   FUNCTION
  2905. *    Returns the Scaliger year.
  2906. *
  2907. *   INPUTS
  2908. *    year     - Heis year
  2909. *
  2910. *   RESULT
  2911. *    syear - The Scaliger year
  2912. *
  2913. *   EXAMPLE
  2914. *    ...
  2915. *    syear = HYearToScaliger(1994);
  2916. *    ...
  2917. *
  2918. *   NOTES
  2919. *    It is better to use this function only from -7 to 8000!
  2920. *
  2921. *   BUGS
  2922. *    The Scaliger period is defined to 3268!!!.
  2923. *
  2924. *   SEE ALSO
  2925. *    JYearToScaliger(),GYearToScaliger()
  2926. *
  2927. *****************************************************************************
  2928. *
  2929. *
  2930. */
  2931.  
  2932.  {/* for compatiblities if GYearToScaliger will be changed */
  2933.   return(GYearToScaliger(year));
  2934.  }
  2935.  
  2936.  /* ----------------------------------------------------------------------- */
  2937.  
  2938.  #ifdef __MakeLib
  2939.    int __saveds __asm ScaligerYearToJ(register __d0 const unsigned int syear)
  2940.  #else
  2941.    int ScaligerYearToJ(const unsigned int syear)
  2942.  #endif
  2943.  
  2944. /*
  2945. ******* Date/ScaligerYearToJ ************************************************
  2946. *
  2947. *   NAME
  2948. *    ScaligerYearToJ -- Returns the Scaliger year as Julian year. (V33)
  2949. *
  2950. *   SYNOPSIS
  2951. *    year = ScaligerYearToJ(syear);
  2952. *     d0            d0
  2953. *
  2954. *    int ScaligerYearToJ(const unsigned int syear);
  2955. *
  2956. *   FUNCTION
  2957. *    Returns the Julian year of a Scaliger year.
  2958. *
  2959. *   INPUTS
  2960. *    syear     - Scaliger year
  2961. *
  2962. *   RESULT
  2963. *    year - The Julian year
  2964. *
  2965. *   EXAMPLE
  2966. *    ...
  2967. *    year = ScaligerYearToJ(4800);
  2968. *    ...
  2969. *
  2970. *   NOTES
  2971. *    It is better to use this function only from 4707 to 6295!
  2972. *
  2973. *   BUGS
  2974. *    unknown.
  2975. *
  2976. *   SEE ALSO
  2977. *    ScaligerYearToG(),ScaligerYearToH()
  2978. *
  2979. *****************************************************************************
  2980. *
  2981. *
  2982. */
  2983.  
  2984.  {if (syear < 4714)
  2985.     return((int)(4714+syear));
  2986.   else
  2987.     return((int)(syear-4713));
  2988.  }
  2989.  
  2990.  
  2991.  #ifdef __MakeLib
  2992.    int __saveds __asm ScaligerYearToG(register __d0 const unsigned int syear)
  2993.  #else
  2994.    int ScaligerYearToG(const unsigned int syear)
  2995.  #endif
  2996.  
  2997. /*
  2998. ******* Date/ScaligerYearToG ************************************************
  2999. *
  3000. *   NAME
  3001. *    ScaligerYearToG -- Returns the Scaliger year as Gregorian year. (V33)
  3002. *
  3003. *   SYNOPSIS
  3004. *    year = ScaligerYearToG(syear);
  3005. *     d0            d0
  3006. *
  3007. *    int ScaligerYearToG(const unsigned int syear);
  3008. *
  3009. *   FUNCTION
  3010. *    Returns the Gregorian year of a Scaliger year.
  3011. *
  3012. *   INPUTS
  3013. *    syear     - Scaliger year
  3014. *
  3015. *   RESULT
  3016. *    year - The Gregorian year
  3017. *
  3018. *   EXAMPLE
  3019. *    ...
  3020. *    year = ScaligerYearToG(6400);
  3021. *    ...
  3022. *
  3023. *   NOTES
  3024. *    It is better to use this function only from 4707 to 7981!
  3025. *
  3026. *   BUGS
  3027. *    unknown.
  3028. *
  3029. *   SEE ALSO
  3030. *    ScaligerYearToJ(),ScaligerYearToH()
  3031. *
  3032. *****************************************************************************
  3033. *
  3034. *
  3035. */
  3036.  
  3037.  {return(ScaligerYearToJ(syear));
  3038.  }
  3039.  
  3040.  
  3041.  #ifdef __MakeLib
  3042.    int __saveds __asm ScaligerYearToH(register __d0 const unsigned int syear)
  3043.  #else
  3044.    int ScaligerYearToH(const unsigned int syear)
  3045.  #endif
  3046.  
  3047. /*
  3048. ******* Date/ScaligerYearToH ************************************************
  3049. *
  3050. *   NAME
  3051. *    ScaligerYearToH -- Returns the Scaliger year as Heis year. (V33)
  3052. *
  3053. *   SYNOPSIS
  3054. *    year = ScaligerYearToH(syear);
  3055. *     d0            d0
  3056. *
  3057. *    int ScaligerYearToH(const unsigned int syear);
  3058. *
  3059. *   FUNCTION
  3060. *    Returns the Heis year of a Scaliger year.
  3061. *
  3062. *   INPUTS
  3063. *    syear     - Scaliger year
  3064. *
  3065. *   RESULT
  3066. *    year - The Heis year
  3067. *
  3068. *   EXAMPLE
  3069. *    ...
  3070. *    year = ScaligerYearToH(7000);
  3071. *    ...
  3072. *
  3073. *   NOTES
  3074. *    It is better to use this function only from 4707 to 7981!
  3075. *
  3076. *   BUGS
  3077. *    unknown.
  3078. *
  3079. *   SEE ALSO
  3080. *    ScaligerYearToJ(),ScaligerYearToG()
  3081. *
  3082. *****************************************************************************
  3083. *
  3084. *
  3085. */
  3086.  
  3087.  {/* for compatibilitie if ScaligerYearToG is changed! */
  3088.   return(ScaligerYearToG(syear));
  3089.  }
  3090.  
  3091.  /* ----------------------------------------------------------------------- */
  3092.  
  3093.  #ifdef __MakeLib
  3094.    unsigned long __saveds __asm JSYearToJD(register __d0 const unsigned int syear)
  3095.  #else
  3096.    unsigned long JSYearToJD(const unsigned int syear)
  3097.  #endif
  3098.  
  3099. /*
  3100. ******* Date/JSYearToJD *****************************************************
  3101. *
  3102. *   NAME
  3103. *    JSYearToJD -- Calcs the JD from a Scaliger year. (V33)
  3104. *
  3105. *   SYNOPSIS
  3106. *    jd = JSYearToJD(syear);
  3107. *    d0         d0
  3108. *
  3109. *    unsigned long JSYearToJD(const unsigned int syear);
  3110. *
  3111. *   FUNCTION
  3112. *    Returns the Julianday of a Scaliger year.
  3113. *
  3114. *   INPUTS
  3115. *    syear     - Scaliger year
  3116. *
  3117. *   RESULT
  3118. *    jd - The Julianday
  3119. *
  3120. *   EXAMPLE
  3121. *    ...
  3122. *    jd = JSYearToJD(4800);
  3123. *    ...
  3124. *
  3125. *   NOTES
  3126. *    It is better to use this function only from 4707 to 6295!
  3127. *
  3128. *   BUGS
  3129. *    unknown.
  3130. *
  3131. *   SEE ALSO
  3132. *    GSYearToJD(),HSYearToJD()
  3133. *
  3134. *****************************************************************************
  3135. *
  3136. *
  3137. */
  3138.  
  3139.  {return(((unsigned long)syear-1)*365+((unsigned long)syear+2) / 4);
  3140.  }
  3141.  
  3142.  
  3143.  #ifdef __MakeLib
  3144.    unsigned long __saveds __asm GSYearToJD(register __d0 const unsigned int syear)
  3145.  #else
  3146.    unsigned long GSYearToJD(const unsigned int syear)
  3147.  #endif
  3148.  
  3149. /*
  3150. ******* Date/GSYearToJD *****************************************************
  3151. *
  3152. *   NAME
  3153. *    GSYearToJD -- Calcs the JD from a Scaliger year. (V33)
  3154. *
  3155. *   SYNOPSIS
  3156. *    jd = GSYearToJD(syear);
  3157. *    d0         d0
  3158. *
  3159. *    unsigned long GSYearToJD(const unsigned int syear);
  3160. *
  3161. *   FUNCTION
  3162. *    Returns the Julianday of a Scaliger year.
  3163. *
  3164. *   INPUTS
  3165. *    syear     - Scaliger year
  3166. *
  3167. *   RESULT
  3168. *    jd - The Julianday
  3169. *
  3170. *   EXAMPLE
  3171. *    ...
  3172. *    jd = GSYearToJD(4800);
  3173. *    ...
  3174. *
  3175. *   NOTES
  3176. *    It is better to use this function only from 4707 to 7981!
  3177. *
  3178. *   BUGS
  3179. *    unknown.
  3180. *
  3181. *   SEE ALSO
  3182. *    JSYearToJD(),HSYearToJD()
  3183. *
  3184. *****************************************************************************
  3185. *
  3186. *
  3187. */
  3188.  
  3189.  {if (syear < 6296)
  3190.     {/* 1583 */
  3191.      return(JSYearToJD(syear));
  3192.     }
  3193.   else
  3194.     return(JSYearToJD(6296)-10+(unsigned long)(GregorianDayDiff(1,1,1583,1,1,ScaligerYearToG(syear))));
  3195.  }
  3196.  
  3197.  
  3198.  #ifdef __MakeLib
  3199.    unsigned long __saveds __asm HSYearToJD(register __d0 const unsigned int syear)
  3200.  #else
  3201.    unsigned long HSYearToJD(const unsigned int syear)
  3202.  #endif
  3203.  
  3204. /*
  3205. ******* Date/HSYearToJD *****************************************************
  3206. *
  3207. *   NAME
  3208. *    HSYearToJD -- Calcs the JD from a Scaliger year. (V33)
  3209. *
  3210. *   SYNOPSIS
  3211. *    jd = HSYearToJD(syear);
  3212. *    d0         d0
  3213. *
  3214. *    unsigned long HSYearToJD(const unsigned int syear);
  3215. *
  3216. *   FUNCTION
  3217. *    Returns the Julianday of a Scaliger year.
  3218. *
  3219. *   INPUTS
  3220. *    syear     - Scaliger year
  3221. *
  3222. *   RESULT
  3223. *    jd - The Julianday
  3224. *
  3225. *   EXAMPLE
  3226. *    ...
  3227. *    jd = HSYearToJD(6700);
  3228. *    ...
  3229. *
  3230. *   NOTES
  3231. *    It is better to use this function only from 4707 to 7981!
  3232. *    In this version only GSYearToJD() is called, because the
  3233. *    Scaliger period is only valid to 3268
  3234. *
  3235. *   BUGS
  3236. *    unknown.
  3237. *
  3238. *   SEE ALSO
  3239. *    JSYearToJD(),GSYearToJD()
  3240. *
  3241. *****************************************************************************
  3242. *
  3243. *
  3244. */
  3245.  
  3246.  {/* for compatibilitie if GSYearToJD is changed! */
  3247.   return(GSYearToJD(syear));
  3248.  }
  3249.  
  3250.  /* ----------------------------------------------------------------------- */
  3251.  
  3252.  #ifdef __MakeLib
  3253.    unsigned long __saveds __asm JDtoMJD(register __d0 const unsigned long jd)
  3254.  #else
  3255.    unsigned long JDtoMJD(const unsigned long jd)
  3256.  #endif
  3257.  
  3258. /*
  3259. ******* Date/JDtoMJD ********************************************************
  3260. *
  3261. *   NAME
  3262. *    JDtoMJD -- Switches from JD to MJD. (V33)
  3263. *
  3264. *   SYNOPSIS
  3265. *    mjd = JDtoMJD(jd);
  3266. *    d0          d0
  3267. *
  3268. *    unsigned long JDtoMJD(const unsigned long jd);
  3269. *
  3270. *   FUNCTION
  3271. *    Returns the Modified Julianday of a Julianday.
  3272. *
  3273. *   INPUTS
  3274. *    jd - Julianday
  3275. *
  3276. *   RESULT
  3277. *    mjd - The Modified Julianday
  3278. *
  3279. *   EXAMPLE
  3280. *    ...
  3281. *    mjd = JDtoMJD(2449354);
  3282. *    ...
  3283. *
  3284. *   NOTES
  3285. *    none
  3286. *
  3287. *   BUGS
  3288. *    Only use this function for jd > 2400001, because mjd is only
  3289. *    defined for this, otherwise system will crash!
  3290. *
  3291. *   SEE ALSO
  3292. *    MJDtoJD()
  3293. *
  3294. *****************************************************************************
  3295. *
  3296. *
  3297. */
  3298.  
  3299.  {return(jd-2400001L);
  3300.  }
  3301.  
  3302.  
  3303.  #ifdef __MakeLib
  3304.    unsigned long __saveds __asm MJDtoJD(register __d0 const unsigned long mjd)
  3305.  #else
  3306.    unsigned long MJDtoJD(const unsigned long mjd)
  3307.  #endif
  3308.  
  3309. /*
  3310. ******* Date/MJDtoJD ********************************************************
  3311. *
  3312. *   NAME
  3313. *    MJDtoJD -- Switches from MJD to JD. (V33)
  3314. *
  3315. *   SYNOPSIS
  3316. *    jd = MJDtoJD(mjd);
  3317. *    d0         d0
  3318. *
  3319. *    unsigned long MJDtoJD(const unsigned long mjd);
  3320. *
  3321. *   FUNCTION
  3322. *    Returns the Julianday of a Modified Julianday.
  3323. *
  3324. *   INPUTS
  3325. *    mjd - Modified Julianday
  3326. *
  3327. *   RESULT
  3328. *    jd - The Julianday
  3329. *
  3330. *   EXAMPLE
  3331. *    ...
  3332. *    jd = JDtoMJD(49353);
  3333. *    ...
  3334. *
  3335. *   NOTES
  3336. *    none
  3337. *
  3338. *   BUGS
  3339. *    unknown.
  3340. *
  3341. *   SEE ALSO
  3342. *    MJDtoJD()
  3343. *
  3344. *****************************************************************************
  3345. *
  3346. *
  3347. */
  3348.  
  3349.  {return(mjd+2400001L);
  3350.  }
  3351.  
  3352.  /* ----------------------------------------------------------------------- */
  3353.  
  3354.  #ifdef __MakeLib
  3355.    unsigned long __saveds __asm JulianToJD(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  3356.  #else
  3357.    unsigned long JulianToJD(const unsigned short day, const unsigned short month, const int year)
  3358.  #endif
  3359.  
  3360. /*
  3361. ******* Date/JulianToJD *****************************************************
  3362. *
  3363. *   NAME
  3364. *    JulianToJD -- Returns the JD for a date. (V33)
  3365. *
  3366. *   SYNOPSIS
  3367. *    jd = JulianToJD(day,month,year);
  3368. *    d0        d0   d1    d2
  3369. *
  3370. *    unsigned long JulianToJD(const unsigned short day,
  3371. *        const unsigned short month, const int year);
  3372. *
  3373. *   FUNCTION
  3374. *    Returns the JD for a Julian date.
  3375. *
  3376. *   INPUTS
  3377. *    day      - day of the date to convert
  3378. *    month    - month of the date to convert
  3379. *    year     - year of the date to convert
  3380. *
  3381. *   RESULT
  3382. *    jd - This is the JD
  3383. *
  3384. *   EXAMPLE
  3385. *    ...
  3386. *    jd = JulianToJD(23,1,1994);
  3387. *    ...
  3388. *
  3389. *   NOTES
  3390. *    It is better to use this function only from -7 to 1582!
  3391. *
  3392. *   BUGS
  3393. *    unknown.
  3394. *
  3395. *   SEE ALSO
  3396. *    JSYearToJD(),JYearToScaliger(),JulianDayDiff(),GregorianToJD(),
  3397. *    HeisToJD()
  3398. *
  3399. *****************************************************************************
  3400. *
  3401. *
  3402. */
  3403.  
  3404.  {return(JSYearToJD(JYearToScaliger(year))+(unsigned long)(JulianDayDiff(1,1,year,day,month,year)));
  3405.  }
  3406.  
  3407.  
  3408.  #ifdef __MakeLib
  3409.    unsigned long __saveds __asm GregorianToJD(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  3410.  #else
  3411.    unsigned long GregorianToJD(const unsigned short day, const unsigned short month, const int year)
  3412.  #endif
  3413.  
  3414. /*
  3415. ******* Date/GregorianToJD **************************************************
  3416. *
  3417. *   NAME
  3418. *    GregorianToJD -- Returns the JD for a date. (V33)
  3419. *
  3420. *   SYNOPSIS
  3421. *    jd = GregorianToJD(day,month,year);
  3422. *    d0           d0   d1    d2
  3423. *
  3424. *    unsigned long GregorianToJD(const unsigned short day,
  3425. *        const unsigned short month, const int year);
  3426. *
  3427. *   FUNCTION
  3428. *    Returns the JD for a Gregorian date.
  3429. *
  3430. *   INPUTS
  3431. *    day      - day of the date to convert
  3432. *    month    - month of the date to convert
  3433. *    year     - year of the date to convert
  3434. *
  3435. *   RESULT
  3436. *    jd - This is the JD
  3437. *
  3438. *   EXAMPLE
  3439. *    ...
  3440. *    jd = GregorianToJD(23,1,1994);
  3441. *    ...
  3442. *
  3443. *   NOTES
  3444. *    It is better to use this function only from -7 to 3200!
  3445. *
  3446. *   BUGS
  3447. *    unknown.
  3448. *
  3449. *   SEE ALSO
  3450. *    GSYearToJD(),GYearToScaliger(),GregorianDayDiff(),JulianToJD(),
  3451. *    HeisToJD()
  3452. *
  3453. *****************************************************************************
  3454. *
  3455. *
  3456. */
  3457.  
  3458.  {return(GSYearToJD(GYearToScaliger(year))+(unsigned long)(GregorianDayDiff(1,1,year,day,month,year)));
  3459.  }
  3460.  
  3461.  
  3462.  #ifdef __MakeLib
  3463.    unsigned long __saveds __asm HeisToJD(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  3464.  #else
  3465.    unsigned long HeisToJD(const unsigned short day, const unsigned short month, const int year)
  3466.  #endif
  3467.  
  3468. /*
  3469. ******* Date/HeisToJD *******************************************************
  3470. *
  3471. *   NAME
  3472. *    HeisToJD -- Returns the JD for a date. (V33)
  3473. *
  3474. *   SYNOPSIS
  3475. *    jd = HeisToJD(day,month,year);
  3476. *    d0          d0   d1    d2
  3477. *
  3478. *    unsigned long HeisToJD(const unsigned short day,
  3479. *        const unsigned short month, const int year);
  3480. *
  3481. *   FUNCTION
  3482. *    Returns the JD for a Heis date.
  3483. *
  3484. *   INPUTS
  3485. *    day      - day of the date to convert
  3486. *    month    - month of the date to convert
  3487. *    year     - year of the date to convert
  3488. *
  3489. *   RESULT
  3490. *    jd - This is the JD
  3491. *
  3492. *   EXAMPLE
  3493. *    ...
  3494. *    jd = HeisToJD(23,1,1994);
  3495. *    ...
  3496. *
  3497. *   NOTES
  3498. *    It is better to use this function only from -7 to 3268!
  3499. *
  3500. *   BUGS
  3501. *    unknown.
  3502. *
  3503. *   SEE ALSO
  3504. *    HSYearToJD(),HYearToScaliger(),HeisDayDiff(),JulianToJD(),HeisToJD()
  3505. *
  3506. *****************************************************************************
  3507. *
  3508. *
  3509. */
  3510.  
  3511.  {return(HSYearToJD(HYearToScaliger(year))+(unsigned long)(HeisDayDiff(1,1,year,day,month,year)));
  3512.  }
  3513.  
  3514.  /* ----------------------------------------------------------------------- */
  3515.  
  3516.  #ifdef __MakeLib
  3517.    float __saveds __asm TimeToJD(register __d0 const unsigned short hour, register __d1 const unsigned short min, register __d2 const unsigned short sec)
  3518.  #else
  3519.    float TimeToJD(const unsigned short hour, const unsigned short min, const unsigned short sec)
  3520.  #endif
  3521.  
  3522. /*
  3523. ******* Date/TimeToJD *******************************************************
  3524. *
  3525. *   NAME
  3526. *    TimeToJD -- Returns the JD for a time. (V33)
  3527. *
  3528. *   SYNOPSIS
  3529. *    jd = TimeToJD(hour,min,sec);
  3530. *    d0           d0   d1  d2
  3531. *
  3532. *    float TimeToJD(const unsigned short hour, const unsigned short min,
  3533. *        const unsigned short sec);
  3534. *
  3535. *   FUNCTION
  3536. *    Returns the JD for a specified time.
  3537. *
  3538. *   INPUTS
  3539. *    hour - hour of the time to convert
  3540. *    min  - minute of the time to convert
  3541. *    sec  - sec. of the time to convert
  3542. *
  3543. *   RESULT
  3544. *    jd - This is the JD time
  3545. *
  3546. *   EXAMPLE
  3547. *    ...
  3548. *    jd = TimeToJD(16,33,0);
  3549. *    ...
  3550. *
  3551. *   NOTES
  3552. *    none
  3553. *
  3554. *   BUGS
  3555. *    There is no check, if the specified time is a valid time!
  3556. *
  3557. *   SEE ALSO
  3558. *    JDToTime()
  3559. *
  3560. *****************************************************************************
  3561. *
  3562. *
  3563. */
  3564.  
  3565.  {return((float)(((unsigned long)hour*3600+(unsigned int)min*60+sec) / 86400.0));
  3566.  }
  3567.  
  3568.  
  3569.  #ifdef __MakeLib
  3570.    void __saveds __asm JDToTime(register __d0 float jd, register __a0 unsigned short *rhour, register __a1 unsigned short *rmin, register __a2 unsigned short *rsec)
  3571.  #else
  3572.    void JDToTime(float jd, unsigned short *rhour, unsigned short *rmin, unsigned short *rsec)
  3573.  #endif
  3574.  
  3575. /*
  3576. ******* Date/JDToTime *******************************************************
  3577. *
  3578. *   NAME
  3579. *    JDToTime -- Returns the real time for a JD time. (V33)
  3580. *
  3581. *   SYNOPSIS
  3582. *    JDToTime(jd,rhour,rmin,rsec);
  3583. *         d0  a0    a1   a2
  3584. *
  3585. *    void JDToTime(float jd, unsigned short *rhour, unsigned short *rmin,
  3586. *        unsigned short *rsec);
  3587. *
  3588. *   FUNCTION
  3589. *    Returns the real time for a JD time.
  3590. *
  3591. *   INPUTS
  3592. *    jd - JD time
  3593. *
  3594. *   RESULT
  3595. *    rhour - 24 hour real time
  3596. *    rmin  - real minutes
  3597. *    rsec  - real seconds
  3598. *
  3599. *   EXAMPLE
  3600. *    ...
  3601. *    JDToTime(0.76543,&rhour,&rmin,&rsec);
  3602. *    ...
  3603. *
  3604. *   NOTES
  3605. *    none.
  3606. *
  3607. *   BUGS
  3608. *    If jd is > 0 (including days) there will be occur arithmetic bugs!
  3609. *
  3610. *   SEE ALSO
  3611. *    TimeToJD()
  3612. *
  3613. *****************************************************************************
  3614. *
  3615. *
  3616. */
  3617.  
  3618.  {unsigned long sec;
  3619.  
  3620.   if (jd > 0.0)
  3621.     jd -= floor(jd);
  3622.   sec = (unsigned long)(jd * 86400.0);
  3623.   *rhour = (unsigned short)(sec / 3600);
  3624.   sec -= (*rhour) * 3600;
  3625.   *rmin = (unsigned short)(sec / 60);
  3626.   sec -= (*rmin) * 60;
  3627.   *rsec = (unsigned short)sec;
  3628.  }
  3629.  
  3630.  /* ----internal----------------------------------------------------------- */
  3631.  
  3632.  static unsigned short GregorianSZ(const unsigned int year)
  3633.  
  3634. /*
  3635. *****i* Date/GregorianSZ ****************************************************
  3636. *
  3637. *   NAME
  3638. *    GregorianSZ -- Returns the 'Sonnenzirkel' (V33)
  3639. *
  3640. *   SYNOPSIS
  3641. *    sz = GregorianSZ(year);
  3642. *
  3643. *    unsigned short GregorianSZ(const unsigned int year);
  3644. *
  3645. *   FUNCTION
  3646. *    Returns the 'Sonnenzirkel' of a year.
  3647. *
  3648. *   INPUTS
  3649. *    year     - For this year the 'Sonnenzirkel' is calculated.
  3650. *
  3651. *   RESULT
  3652. *    sz - The 'Sonnenzirkel' for the specified year.
  3653. *
  3654. *   EXAMPLE
  3655. *    ...
  3656. *    sz = GregorianSZ(1994);
  3657. *    ...
  3658. *
  3659. *   NOTES
  3660. *    Use this only for 1582 to 4100!
  3661. *
  3662. *   BUGS
  3663. *    unknown.
  3664. *
  3665. *   SEE ALSO
  3666. *    GYearToScaliger()
  3667. *
  3668. *****************************************************************************
  3669. *
  3670. *
  3671. */
  3672.  
  3673.  {unsigned short gz;
  3674.   gz = (unsigned short)(GYearToScaliger(year) % 28);
  3675.   if (gz==0)
  3676.     gz = 28;
  3677.   return(gz);
  3678.  }
  3679.  
  3680.  
  3681.  static unsigned short GregorianGZ(const unsigned int year)
  3682.  
  3683. /*
  3684. *****i* Date/GregorianGZ ****************************************************
  3685. *
  3686. *   NAME
  3687. *    GregorianGZ -- Returns the 'Goldene Zahl' (golden number) (V33)
  3688. *
  3689. *   SYNOPSIS
  3690. *    gz = GregorianGZ(year);
  3691. *
  3692. *    unsigned short GregorianGZ(const unsigned int year);
  3693. *
  3694. *   FUNCTION
  3695. *    Returns the 'Goldene Zahl' of a year.
  3696. *
  3697. *   INPUTS
  3698. *    year     - For this year the 'Goldene Zahl' is calculated.
  3699. *
  3700. *   RESULT
  3701. *    gz - The 'Goldene Zahl' for the specified year.
  3702. *
  3703. *   EXAMPLE
  3704. *    ...
  3705. *    gz = GregorianGZ(1994);
  3706. *    ...
  3707. *
  3708. *   NOTES
  3709. *    Use this only for 1582 to 4100!
  3710. *
  3711. *   BUGS
  3712. *    unknown.
  3713. *
  3714. *   SEE ALSO
  3715. *    GYearToScaliger()
  3716. *
  3717. *****************************************************************************
  3718. *
  3719. *
  3720. */
  3721.  
  3722.  {unsigned int syear;
  3723.  
  3724.   syear = GYearToScaliger(year) % 19;
  3725.   if (syear == 0)
  3726.     syear = 19;
  3727.   return((unsigned short)syear);
  3728.  }
  3729.  
  3730.  
  3731.  static unsigned short GEP(const unsigned int year)
  3732.  
  3733. /*
  3734. *****i* Date/GEP ************************************************************
  3735. *
  3736. *   NAME
  3737. *    GEP -- Internal function to help calculate the 'EP' (V33)
  3738. *
  3739. *   SYNOPSIS
  3740. *    hep = GEP(year);
  3741. *
  3742. *    unsigned short GEP(const unsigned int year);
  3743. *
  3744. *   FUNCTION
  3745. *    Internal function to help calculate the 'EP'
  3746. *
  3747. *   INPUTS
  3748. *    year - This is the year for which the help EP is to be
  3749. *        calculated
  3750. *
  3751. *   RESULT
  3752. *    hep - The help value for the EP calculation.
  3753. *
  3754. *   EXAMPLE
  3755. *    ...
  3756. *    hep = GEP(1994);
  3757. *    ...
  3758. *
  3759. *   NOTES
  3760. *    Use this only for 1582 to 4200!
  3761. *
  3762. *   BUGS
  3763. *    unknown.
  3764. *
  3765. *   SEE ALSO
  3766. *
  3767. *
  3768. *****************************************************************************
  3769. *
  3770. *
  3771. */
  3772.  
  3773.    {unsigned short    century,decade;
  3774.     int            ep;
  3775.  
  3776.     ep = 1; /* 1582 */
  3777.     century = (unsigned short)(year / 100);
  3778.     decade = (unsigned short)(year - century * 100);
  3779.     if (year < 1701)
  3780.       return(1);
  3781.     else
  3782.       if (year < 1800)
  3783.         return(0);
  3784.       else
  3785.         {ep -= (int)(((century) % 4) + (((century-16) / 4) * 3));
  3786.          if ((decade == 0) && ((century % 4) > 0))
  3787.            ep++;
  3788.          ep += (int)((century-18) / 3);
  3789.          if ((((century-18) % 3) > 0) || (decade > 0))
  3790.            ep++;
  3791.          if (ep > 29)
  3792.            ep %= 30;
  3793.          if (ep < 0)
  3794.            ep += 30;
  3795.          return((unsigned short)ep);
  3796.         }
  3797.    }
  3798.  
  3799.  
  3800.  static unsigned short GregorianEP(const unsigned int year)
  3801.  
  3802. /*
  3803. *****i* Date/GregorianEP ****************************************************
  3804. *
  3805. *   NAME
  3806. *    GregorianEP -- Returns the 'Epakte' (V33)
  3807. *
  3808. *   SYNOPSIS
  3809. *    ep = GregorianEP(year);
  3810. *
  3811. *    unsigned short GregorianEP(const unsigned int year);
  3812. *
  3813. *   FUNCTION
  3814. *    Returns the 'Epakte' of a year.
  3815. *
  3816. *   INPUTS
  3817. *    year     - For this year the 'Epakte' is calculated.
  3818. *
  3819. *   RESULT
  3820. *    ep - The 'Epakte' for the specified year.
  3821. *
  3822. *   EXAMPLE
  3823. *    ...
  3824. *    ep = GregorianEP(1994);
  3825. *    ...
  3826. *
  3827. *   NOTES
  3828. *    Use this only for 1582 to 4100!
  3829. *
  3830. *   BUGS
  3831. *    unknown.
  3832. *
  3833. *   SEE ALSO
  3834. *    GEP(),GregorianGZ()
  3835. *
  3836. *****************************************************************************
  3837. *
  3838. *
  3839. */
  3840.  
  3841.  {unsigned short ep;
  3842.  
  3843.   if (year >= 1582)
  3844.    {
  3845.     ep = (unsigned short)(((GregorianGZ(year)-1)*11 + GEP(year)) % 30);
  3846.     if (ep == 0)
  3847.       ep = 30;
  3848.     return(ep);
  3849.    }
  3850.   else
  3851.     return(31);
  3852.  }
  3853.  
  3854.  
  3855.  static unsigned short GregorianJHStartSB(const unsigned short century)
  3856.  
  3857. /*
  3858. *****i* Date/GregorianJHStartSB *********************************************
  3859. *
  3860. *   NAME
  3861. *    GregorianJHStartSB -- Returns the 'Sonntagsbuchstabe' (V33)
  3862. *
  3863. *   SYNOPSIS
  3864. *    csb = GregorianJHStartSB(century);
  3865. *
  3866. *    unsigned short GregorianJHStartSB(const unsigned short century);
  3867. *
  3868. *   FUNCTION
  3869. *    Returns start 'SB' for a century.
  3870. *
  3871. *   INPUTS
  3872. *    century - For this century the start 'SB' is calculated.
  3873. *
  3874. *   RESULT
  3875. *    csb - The start 'SB' for the specified century.
  3876. *
  3877. *   EXAMPLE
  3878. *    ...
  3879. *    csb = GregorianJHStartSB(19);
  3880. *    ...
  3881. *
  3882. *   NOTES
  3883. *    Use this only for 15 to 31!
  3884. *
  3885. *   BUGS
  3886. *    unknown.
  3887. *
  3888. *   SEE ALSO
  3889. *    GregorianJHStartSB()
  3890. *
  3891. *****************************************************************************
  3892. *
  3893. *
  3894. */
  3895.  
  3896.  {unsigned short sb;
  3897.  
  3898.   if (century == 15)
  3899.     return(4);
  3900.   else
  3901.    {
  3902.     sb = GregorianJHStartSB(century-1);
  3903.     if ((century % 4) > 0)
  3904.       sb++;
  3905.     sb %= 7;
  3906.     if (sb == 0)
  3907.       sb = 7;
  3908.     return(sb);
  3909.    }
  3910.  }
  3911.  
  3912.  
  3913.  static unsigned short GregorianJHSB(const unsigned int year)
  3914.  
  3915. /*
  3916. *****i* Date/GregorianSB ****************************************************
  3917. *
  3918. *   NAME
  3919. *    GregorianJHSB -- Returns the 'Sonntagsbuchstabe' (V33)
  3920. *
  3921. *   SYNOPSIS
  3922. *    sb = GregorianJHSB(year);
  3923. *
  3924. *    unsigned short GregorianJHSB(const unsigned int year);
  3925. *
  3926. *   FUNCTION
  3927. *    Returns the start 'SB' for a century year.
  3928. *
  3929. *   INPUTS
  3930. *    year - For this century year the start 'SB' is calculated.
  3931. *
  3932. *   RESULT
  3933. *    sb - The start 'SB' for the specified year.
  3934. *
  3935. *   EXAMPLE
  3936. *    ...
  3937. *    sb = GregorianJHSB(1994);
  3938. *    ...
  3939. *
  3940. *   NOTES
  3941. *    Use this only for 1583 to 3199!
  3942. *
  3943. *   BUGS
  3944. *    unknown.
  3945. *
  3946. *   SEE ALSO
  3947. *    GregorianLeapYear(),GregorianJHStartSB()
  3948. *
  3949. *****************************************************************************
  3950. *
  3951. *
  3952. */
  3953.  
  3954.  {
  3955.   if (((year % 100) == 0) && (!GregorianLeapYear((int)year)))
  3956.     return((unsigned short)(((year / 100) % 4) *2 +1));
  3957.   else
  3958.     return(GregorianJHStartSB(year / 100));
  3959.  }
  3960.  
  3961.  
  3962.  static unsigned short GregorianSB(const unsigned int year)
  3963.  
  3964. /*
  3965. *****i* Date/GregorianSB ****************************************************
  3966. *
  3967. *   NAME
  3968. *    GregorianSB -- Returns the 'Sonntagsbuchstabe' (V33)
  3969. *
  3970. *   SYNOPSIS
  3971. *    sb = GregorianSB(year);
  3972. *
  3973. *    unsigned short GregorianSB(const unsigned int year);
  3974. *
  3975. *   FUNCTION
  3976. *    Returns the 'SB' for a year.
  3977. *
  3978. *   INPUTS
  3979. *    year - For this year the 'SB' is calculatet.
  3980. *
  3981. *   RESULT
  3982. *    sb - The 'SB' for the specified year.
  3983. *        This means the day the first Sunday lies on :)
  3984. *
  3985. *   EXAMPLE
  3986. *    ...
  3987. *    sb = GregorianSB(1994);
  3988. *    ...
  3989. *
  3990. *   NOTES
  3991. *    Use this only for 1583 to 3199!
  3992. *
  3993. *   BUGS
  3994. *    unknown.
  3995. *
  3996. *   SEE ALSO
  3997. *    GregorianLeapYear(),GregorianSZ(),GregorianJHStartSB()
  3998. *
  3999. *****************************************************************************
  4000. *
  4001. *
  4002. */
  4003.  
  4004.  {unsigned short sz,csb,i;
  4005.  
  4006.   if (((year % 100) == 0) && (!GregorianLeapYear((int)year)))
  4007.     return((unsigned short)(((year / 100) % 4) *2 +1));
  4008.   else
  4009.    {
  4010.     sz = GregorianSZ(year);
  4011.     csb = GregorianJHStartSB(year / 100);
  4012.     if (sz == 28)
  4013.       return(csb);
  4014.     else
  4015.      {
  4016.       for (i=27;i>=sz;i--)
  4017.        {
  4018.         csb++;
  4019.         if (csb == 8)
  4020.           csb = 1;
  4021.         if (((i-1) % 4) == 0)
  4022.          {
  4023.           csb++;
  4024.           if (csb == 8)
  4025.             csb =1;
  4026.          }
  4027.        }
  4028.       return(csb);
  4029.      }
  4030.    }
  4031.  }
  4032.  
  4033.  
  4034.  static unsigned short MoonMonthAge(const unsigned short month, unsigned short ep, const int year)
  4035.  
  4036. /*
  4037. *****i* Date/MoonMonthAge ***************************************************
  4038. *
  4039. *   NAME
  4040. *    MoonMonthAge -- Calculates the age of the moon on month start (V33)
  4041. *
  4042. *   SYNOPSIS
  4043. *    ep = MoonMonthAge(month,ep);
  4044. *
  4045. *    unsigned short MoonMonthAge(unsigned short month, unsigned short ep,
  4046. *        const int year);
  4047. *
  4048. *   FUNCTION
  4049. *    Returns the age of the moon on the start of a month.
  4050. *
  4051. *   INPUTS
  4052. *    month - Month for which the age of the moon is needed.
  4053. *    ep    - 'Epakte' of the New Years day.
  4054. *
  4055. *   RESULT
  4056. *    ep - The moonage on the 1. of the specified month.
  4057. *
  4058. *   EXAMPLE
  4059. *    ...
  4060. *    ep = MoonMonthAge(2,17); / * 17 is for 1994 * /
  4061. *    ...
  4062. *
  4063. *   NOTES
  4064. *    This is only a experimental version!
  4065. *
  4066. *   BUGS
  4067. *    unknown.
  4068. *
  4069. *   SEE ALSO
  4070. *    MoonMonthAge(),GregorianMonthDays()
  4071. *
  4072. *****************************************************************************
  4073. *
  4074. *
  4075. */
  4076.  
  4077.    {if (month == 1)
  4078.       return(ep);
  4079.     else
  4080.       if (month % 2 == 0)
  4081.         ep = (unsigned short)((MoonMonthAge(month-1,ep,year) + GregorianMonthDays(month-1,year)) % 29);
  4082.       else
  4083.         ep = (unsigned short)((MoonMonthAge(month-1,ep,year) + GregorianMonthDays(month-1,year)) % 30);
  4084.       return(ep);
  4085.    }
  4086.  
  4087.  /* ----------------------------------------------------------------------- */
  4088.  
  4089.  #ifdef __MakeLib
  4090.    unsigned short __saveds __asm GregorianMoonAge(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  4091.  #else
  4092.    unsigned short GregorianMoonAge(const unsigned short day, const unsigned short month, const int year)
  4093.  #endif
  4094.  
  4095. /*
  4096. ******* Date/GregorianMoonAge ***********************************************
  4097. *
  4098. *   NAME
  4099. *    GregorianMoonAge -- Returns the age of the moon (V33)
  4100. *
  4101. *   SYNOPSIS
  4102. *    ep = GregorianMoonAge(day,month,year);
  4103. *    d0               d0   d1   d2
  4104. *
  4105. *    unsigned short GregorianMoonAge(const unsigned short day,
  4106. *        const unsigned short month, const int year);
  4107. *
  4108. *   FUNCTION
  4109. *    Returns the age of the moon on a specified date.
  4110. *
  4111. *   INPUTS
  4112. *    day   - For this day the age is calculated.
  4113. *    month - For this month the age is calculated.
  4114. *    year  - For this year the age is calculated.
  4115. *
  4116. *   RESULT
  4117. *    ep - The age of the moon on the specified date.
  4118. *
  4119. *   EXAMPLE
  4120. *    ...
  4121. *    ep = GregorianMoonAge(18,9,1994);
  4122. *    ...
  4123. *
  4124. *   NOTES
  4125. *    Use this only for 1582 to 4100!
  4126. *    This is only a experimental version!
  4127. *
  4128. *   BUGS
  4129. *    unknown.
  4130. *
  4131. *   SEE ALSO
  4132. *    MoonMonthAge(),GregorianEP(),GregorianMoonPhase()
  4133. *
  4134. *****************************************************************************
  4135. *
  4136. *
  4137. */
  4138.  
  4139.  {unsigned short ep;
  4140.  
  4141.   ep = GregorianEP(year);
  4142.   ep = MoonMonthAge(month,ep,year);
  4143.   ep += day -1;
  4144.   if (month > 1)
  4145.     if (month % 2 == 0)
  4146.       {ep %= 30;
  4147.        if (ep == 0)
  4148.          ep = 30;
  4149.       }
  4150.     else
  4151.       {ep %= 29;
  4152.        if (ep == 0)
  4153.          ep = 29;
  4154.       }
  4155.   else
  4156.     if (ep > 29)
  4157.       ep %= 29;
  4158.   return(ep);
  4159.  }
  4160.  
  4161.  
  4162.  #ifdef __MakeLib
  4163.    void __saveds __asm JulianEaster(register __d0 const int year, register __a0 unsigned short *dday, register __a1 unsigned short *dmonth)
  4164.  #else
  4165.    void JulianEaster(const int year, unsigned short *dday, unsigned short *dmonth)
  4166.  #endif
  4167.  
  4168. /*
  4169. ******* Date/JulianEaster ***************************************************
  4170. *
  4171. *   NAME
  4172. *    JulianEaster -- Returns the date of eastern in a year (V33.097)
  4173. *
  4174. *   SYNOPSIS
  4175. *    JulianEaster(year,dday,dmonth);
  4176. *              d0   a0    a1
  4177. *
  4178. *    void JulianEaster(const int year, unsigned short *dday,
  4179. *        unsigned short *dmonth);
  4180. *
  4181. *   FUNCTION
  4182. *    Returns the date of eastern for a specified year.
  4183. *
  4184. *   INPUTS
  4185. *    year  - eastern is calculated for this year
  4186. *
  4187. *   RESULT
  4188. *    dday   - day of easter-Sunday
  4189. *    dmonth - month of easter-Sunday
  4190. *
  4191. *   EXAMPLE
  4192. *    ...
  4193. *    JulianEaster(1994,&dday,&dmonth);
  4194. *    ...
  4195. *
  4196. *   NOTES
  4197. *    Use this only for 31 to 1582!
  4198. *
  4199. *   BUGS
  4200. *    None.
  4201. *
  4202. *   SEE ALSO
  4203. *    GregorianEaster(),HeisEaster()
  4204. *
  4205. *****************************************************************************
  4206. *
  4207. *
  4208. */
  4209.  
  4210.  {
  4211.   unsigned short a,b,c;
  4212.  
  4213.   a = (19*(year%19)+15)%30;
  4214.   b = (2*(year%4)+4*(year%7)-a+34)%7;
  4215.   c = a+b+114;
  4216.   *dday = c%31 +1;
  4217.   *dmonth = c/31;
  4218.  }
  4219.  
  4220. /*
  4221.  #ifdef __MakeLib
  4222.    void __saveds __asm GregorianEaster(register __d0 const int year, register __a0 unsigned short *dday, register __a1 unsigned short *dmonth)
  4223.  #else
  4224.    void GregorianEaster(const int year, unsigned short *dday, unsigned short *dmonth)
  4225.  #endif
  4226.  
  4227. / *
  4228. *****i* Date/GregorianEaster ************************************************
  4229. *
  4230. *   NAME
  4231. *    GregorianEaster -- Returns the date of eastern in a year (V33)
  4232. *
  4233. *   SYNOPSIS
  4234. *    GregorianEaster(year,dday,dmonth);
  4235. *             d0   a0    a1
  4236. *
  4237. *    void GregorianEaster(const int year, unsigned short *dday,
  4238. *        unsigned short *dmonth);
  4239. *
  4240. *   FUNCTION
  4241. *    Returns the date of eastern for a specified year.
  4242. *
  4243. *   INPUTS
  4244. *    year  - eastern is calculated for this year
  4245. *
  4246. *   RESULT
  4247. *    dday   - day of easter-Sunday
  4248. *    dmonth - month of easter-Sunday
  4249. *
  4250. *   EXAMPLE
  4251. *    ...
  4252. *    GregorianEaster(1994,&dday,&dmonth);
  4253. *    ...
  4254. *
  4255. *   NOTES
  4256. *    Use this only for 1900 to 2099!
  4257. *    Tested for 1977-1994! But this formula is from Gauß - so it must be
  4258. *    correct :) but extended by me (hope this will be a good thing too!)
  4259. *
  4260. *   BUGS
  4261. *    None.
  4262. *
  4263. *   SEE ALSO
  4264. *    GEP(),GregorianJHSB()
  4265. *
  4266. *****************************************************************************
  4267. *
  4268. *
  4269. * /
  4270.  
  4271.  {unsigned short a,d,e,f;
  4272.   short M,N;
  4273.  
  4274.   M = (short)((30 - GEP(year)) - 7);
  4275.   if (M < 0)
  4276.     M += 30;
  4277.   N = (short)(GregorianJHSB(year)-2);
  4278.   if (N<1)
  4279.     N += 7;
  4280.   a = (unsigned short)(year % 19);
  4281.   d = (unsigned short)((19*(unsigned int)a+M) % 30);
  4282.   e = (unsigned short)((2*(unsigned int)(year % 4)+4*(unsigned int)(year % 7)+6*(unsigned int)(d)+N) % 7);
  4283.   f = (unsigned short)(d+e);
  4284.  
  4285.   if (f < 10)
  4286.    {/ * märz * /
  4287.     *dmonth = 3;
  4288.     *dday = (unsigned short)(22+f);
  4289.    }
  4290.   else
  4291.    {/ * april * /
  4292.     *dmonth = 4;
  4293.     *dday = (unsigned short)(f-9);
  4294.     if (*dday==26)
  4295.       *dday = 19;
  4296.     else
  4297.       if ((*dday==25) && (d==28) && (a>10))
  4298.         *dday = 18;
  4299.    }
  4300.  }
  4301. */
  4302.  
  4303.  #ifdef __MakeLib
  4304.    void __saveds __asm GregorianEaster(register __d0 const int year, register __a0 unsigned short *dday, register __a1 unsigned short *dmonth)
  4305.  #else
  4306.    void GregorianEaster(const int year, unsigned short *dday, unsigned short *dmonth)
  4307.  #endif
  4308.  
  4309. /*
  4310. ******* Date/GregorianEaster ************************************************
  4311. *
  4312. *   NAME
  4313. *    GregorianEaster -- Returns the date of eastern in a year (V33)
  4314. *
  4315. *   SYNOPSIS
  4316. *    GregorianEaster(year,dday,dmonth);
  4317. *             d0   a0    a1
  4318. *
  4319. *    void GregorianEaster(const int year, unsigned short *dday,
  4320. *        unsigned short *dmonth);
  4321. *
  4322. *   FUNCTION
  4323. *    Returns the date of eastern for a specified year.
  4324. *
  4325. *   INPUTS
  4326. *    year  - eastern is calculated for this year
  4327. *
  4328. *   RESULT
  4329. *    dday   - day of easter-Sunday
  4330. *    dmonth - month of easter-Sunday
  4331. *
  4332. *   EXAMPLE
  4333. *    ...
  4334. *    GregorianEaster(1994,&dday,&dmonth);
  4335. *    ...
  4336. *
  4337. *   NOTES
  4338. *    Use this only for 31 to 2099!
  4339. *
  4340. *   BUGS
  4341. *    None.
  4342. *
  4343. *   SEE ALSO
  4344. *    JulianEaster(),HeisEaster()
  4345. *
  4346. *****************************************************************************
  4347. *
  4348. *
  4349. */
  4350.  
  4351.  {
  4352.   unsigned short a,b,c,d,e;
  4353.   unsigned int f;
  4354.  
  4355.   if (year < 1583)
  4356.    {
  4357.     JulianEaster(year,dday,dmonth);
  4358.    }
  4359.   else
  4360.    {
  4361.     a = year % 19;
  4362.     b = year / 100;
  4363.     c = year % 100;
  4364.     d = (19*a+b-(b/4)-((b-((b+8)/25)+1)/3)+15) % 30;
  4365.     e = (32+2*(b%4)+2*(c/4)-d-(c%4)) % 7;
  4366.     f = d+e-7*((a+11*d+22*e)/451)+114;
  4367.     *dday = f%31 +1;
  4368.     *dmonth = f/31;
  4369.    }
  4370.  }
  4371.  
  4372.  
  4373.  #ifdef __MakeLib
  4374.    void __saveds __asm HeisEaster(register __d0 const int year, register __a0 unsigned short *dday, register __a1 unsigned short *dmonth)
  4375.  #else
  4376.    void HeisEaster(const int year, unsigned short *dday, unsigned short *dmonth)
  4377.  #endif
  4378.  
  4379. /*
  4380. ******* Date/HeisEaster *****************************************************
  4381. *
  4382. *   NAME
  4383. *    HeisEaster -- Returns the date of eastern in a year (V33)
  4384. *
  4385. *   SYNOPSIS
  4386. *    HeisEaster(year,dday,dmonth);
  4387. *            d0   a0    a1
  4388. *
  4389. *    void HeisEaster(const int year, unsigned short *dday,
  4390. *        unsigned short *dmonth);
  4391. *
  4392. *   FUNCTION
  4393. *    Returns the date of eastern for a specified year.
  4394. *
  4395. *   INPUTS
  4396. *    year  - eastern is calculated for this year
  4397. *
  4398. *   RESULT
  4399. *    dday   - day of easter-Sunday
  4400. *    dmonth - month of easter-Sunday
  4401. *
  4402. *   EXAMPLE
  4403. *    ...
  4404. *    HeisEaster(1994,&dday,&dmonth);
  4405. *    ...
  4406. *
  4407. *   NOTES
  4408. *    This is only a dummy to GregorianEaster!
  4409. *    Use this only for 31 to 2099!
  4410. *
  4411. *   BUGS
  4412. *    Unknown.
  4413. *
  4414. *   SEE ALSO
  4415. *    JulianEaster(),GregorianEaster()
  4416. *
  4417. *****************************************************************************
  4418. *
  4419. *
  4420. */
  4421.  
  4422.  {
  4423.   GregorianEaster(year,dday,dmonth);
  4424.  }
  4425.  
  4426.  
  4427.  /* ----------------------------------------------------------------------- */
  4428.  
  4429.  #ifdef __MakeLib
  4430.    short __saveds __asm TimeZoneFactor(register __d0 const short degree)
  4431.  #else
  4432.    short TimeZoneFactor(const short degree)
  4433.  #endif
  4434.  
  4435. /*
  4436. ******* Date/TimeZoneFactor *************************************************
  4437. *
  4438. *   NAME
  4439. *    TimeZoneFactor -- Returns the value you have to add to GMT time (V33)
  4440. *
  4441. *   SYNOPSIS
  4442. *    addhours = TimeZoneFactor(degrees);
  4443. *       d0                d0
  4444. *
  4445. *    short TimeZoneFactor(const short degree);
  4446. *
  4447. *   FUNCTION
  4448. *    This gives you the hours you have to add to GMT time,
  4449. *    specified on the fact, that a timezone is 15 degrees
  4450. *    and that GMT is centered on 0 degrees!
  4451. *
  4452. *   INPUTS
  4453. *    degrees - Position of timezone you live in
  4454. *    (from -180 east to +180 west)
  4455. *
  4456. *   RESULT
  4457. *    addhours - Time to add to GMT time to get your locale zone time
  4458. *        (-12 to +12)
  4459. *
  4460. *   EXAMPLE
  4461. *    ...
  4462. *    addhours = TimeZoneFactor(-8);
  4463. *    ...
  4464. *
  4465. *   NOTES
  4466. *    none
  4467. *
  4468. *   BUGS
  4469. *    No errorcheck, if you put in valid degrees (-180 to +180)
  4470. *    Only full degrees are supportet, keep sure that you
  4471. *    round in the right way for 0.x degree places
  4472. *    I am not sure about the correct +/- behaviour!!!
  4473. *
  4474. *   SEE ALSO
  4475. *
  4476. *
  4477. *****************************************************************************
  4478. *
  4479. *
  4480. */
  4481.  
  4482.  {if (degree >= 0)
  4483.     return((short)(degree / 15.0 + 0.5));
  4484.   else
  4485.     return((short)(degree / 15.0 - 0.5));
  4486.  }
  4487.  
  4488.  
  4489.  #ifdef __MakeLib
  4490.    long __saveds __asm LMT(register __d0 const unsigned long secs, register __d1 const float meridiandegree, register __d2 const float posdegree)
  4491.  #else
  4492.    long LMT(const unsigned long secs, const float meridiandegree, const float posdegree)
  4493.  #endif
  4494.  
  4495. /*
  4496. ******* Date/LMT ************************************************************
  4497. *
  4498. *   NAME
  4499. *    LMT -- Calculates your local time in your timezone (V33)
  4500. *
  4501. *   SYNOPSIS
  4502. *    secs = LMT(secs,meridian,pos);
  4503. *     d0        d0     d1    d2
  4504. *
  4505. *    unsigned long LMT(const unsigned long secs,
  4506. *        const float meridiandegree, const float posdegree);
  4507. *
  4508. *   FUNCTION
  4509. *    Calculates your Local Mean Time of your place!
  4510. *
  4511. *   INPUTS
  4512. *    secs     - Seconds of the running day (hours*3600+min*60+sec)
  4513. *    meridian - Degrees of your timezone-meridian
  4514. *    pos      - Degrees of your place
  4515. *
  4516. *   RESULT
  4517. *    secs - Local seconds of the running day
  4518. *
  4519. *   EXAMPLE
  4520. *    ...
  4521. *    secs = LMT(76080,-15.0,-8.923055556);
  4522. *    ...
  4523. *
  4524. *   NOTES
  4525. *    none
  4526. *
  4527. *   BUGS
  4528. *    No errorcheck, if you put in valid degrees (-180 to +180)
  4529. *
  4530. *   SEE ALSO
  4531. *
  4532. *
  4533. *****************************************************************************
  4534. *
  4535. *
  4536. */
  4537.  
  4538.  {return((long)secs + (long)((meridiandegree / 15.0 - posdegree / 15.0)*3600.0));
  4539.  }
  4540.  
  4541.  
  4542.  #ifdef __MakeLib
  4543.    unsigned long __saveds __asm TimeToSec(register __d0 const unsigned short hour, register __d1 const unsigned short min, register __d2 const unsigned short sec)
  4544.  #else
  4545.    unsigned long TimeToSec(const unsigned short hour, const unsigned short min, const unsigned short sec)
  4546.  #endif
  4547.  
  4548. /*
  4549. ******* Date/TimeToSec ******************************************************
  4550. *
  4551. *   NAME
  4552. *    TimeToSec -- Returns the time in seconds (V33)
  4553. *
  4554. *   SYNOPSIS
  4555. *    secs = TimeToSec(hour,min,sec);
  4556. *     d0          d0   d1  d2
  4557. *
  4558. *    unsigned long TimeToSec(const unsigned short hour,
  4559. *        const unsigned short min, const unsigned short sec);
  4560. *
  4561. *   FUNCTION
  4562. *    Gives you back the time in seconds
  4563. *
  4564. *   INPUTS
  4565. *    hour - hours you want (0-23)
  4566. *    min  - minutes you want (0-59)
  4567. *    sec  - seconds you want (0-59)
  4568. *
  4569. *   RESULT
  4570. *    secs - Time in seconds
  4571. *
  4572. *   EXAMPLE
  4573. *    ...
  4574. *    secs = TimeToSec(21,15,00);
  4575. *    ...
  4576. *
  4577. *   NOTES
  4578. *    Don't forget to convert AM/PM time to 24h time!
  4579. *
  4580. *   BUGS
  4581. *    No errorcheck, if you use a valid time
  4582. *
  4583. *   SEE ALSO
  4584. *    SecToTime()
  4585. *
  4586. *****************************************************************************
  4587. *
  4588. *
  4589. */
  4590.  
  4591.  {return((unsigned long)hour*3600+(unsigned long)min*60+sec);
  4592.  }
  4593.  
  4594.  
  4595.  #ifdef __MakeLib
  4596.    void __saveds __asm SecToTime(register __d0 unsigned long secs, register __a0 unsigned short *hour, register __a1 unsigned short *min, register __a2 unsigned short *sec)
  4597.  #else
  4598.    void SecToTime(unsigned long secs, unsigned short *hour, unsigned short *min, unsigned short *sec)
  4599.  #endif
  4600.  
  4601. /*
  4602. ******* Date/SecToTime ******************************************************
  4603. *
  4604. *   NAME
  4605. *    SecToTime -- Returns the time from seconds (V33)
  4606. *
  4607. *   SYNOPSIS
  4608. *    SecToTime(secs,hour,min,sec);
  4609. *           d0   a0   a1  a2
  4610. *
  4611. *    SecToTime(unsigned long secs, unsigned short *hour,
  4612. *        unsigned short *min, unsigned short *sec);
  4613. *
  4614. *   FUNCTION
  4615. *    Gives you back the time from the specified seconds
  4616. *
  4617. *   INPUTS
  4618. *    secs - Time in seconds
  4619. *
  4620. *   RESULT
  4621. *    hour - hours (0-23)
  4622. *    min  - minutes (0-59)
  4623. *    sec  - seconds (0-59)
  4624. *
  4625. *   EXAMPLE
  4626. *    ...
  4627. *    SecToTime(76860,&hour,&min,&sec);
  4628. *    ...
  4629. *
  4630. *   NOTES
  4631. *    Don't forget to convert 24h time to AM/PM time if needed!
  4632. *
  4633. *   BUGS
  4634. *    No errorcheck, if you use a valid time
  4635. *
  4636. *   SEE ALSO
  4637. *    TimeToSec()
  4638. *
  4639. *****************************************************************************
  4640. *
  4641. *
  4642. */
  4643.  
  4644.  {*hour = (unsigned short)(secs / 3600);
  4645.   secs -= (unsigned long)(*hour) * 3600;
  4646.   *min = (unsigned short)(secs / 60);
  4647.   *sec = (unsigned short)(secs - (unsigned long)(*min) * 60);
  4648.  }
  4649.  
  4650.  /* ----------------------------------------------------------------------- */
  4651.  
  4652.  #ifdef __MakeLib
  4653.    unsigned short __saveds __asm JulianWeek(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  4654.  #else
  4655.    unsigned short JulianWeek(const unsigned short day, const unsigned short month, const int year)
  4656.  #endif
  4657.  
  4658. /*
  4659. ******* Date/JulianWeek *****************************************************
  4660. *
  4661. *   NAME
  4662. *    JulianWeek -- Gets the weeknumber of a specified date. (V33)
  4663. *
  4664. *   SYNOPSIS
  4665. *    weeknr = JulianWeek(day,month,year);
  4666. *      d0            d0    d1   d2
  4667. *
  4668. *    unsigned short JulianWeek(const unsigned short day,
  4669. *        const unsigned short month, const int year);
  4670. *
  4671. *   FUNCTION
  4672. *    JulianWeek gets the weeknumber for a specified date.
  4673. *
  4674. *   INPUTS
  4675. *    day   - day of the date
  4676. *    month - month of the date
  4677. *    year  - year of the date
  4678. *
  4679. *   RESULT
  4680. *    week - This is the number of the week the specified date lies in.
  4681. *        If the first day in a new year is a Friday, Saturday or
  4682. *        Sunday, this would be the last week of the last year!
  4683. *        If the 29.12. is a Monday, the 30.12. is a Monday or a Tuesday,
  4684. *        the 31.12. is a Monday, Tuesday or a Wednesday this is the
  4685. *        first week of the next year!
  4686. *
  4687. *   EXAMPLE
  4688. *    ...
  4689. *    weeknr = JulianWeek(4,10,1582);
  4690. *    ...
  4691. *
  4692. *   NOTES
  4693. *    It is is better only to use this function for years from 0 to 1582!
  4694. *
  4695. *   BUGS
  4696. *    For years < 0 errors could occur.
  4697. *
  4698. *   SEE ALSO
  4699. *    GregorianWeek(),HeisWeek(),JulianWeekday(),JulianDayDiff()
  4700. *
  4701. *****************************************************************************
  4702. *
  4703. *
  4704. */
  4705.  
  4706.  {long days;
  4707.   Weekdays firstweekday;
  4708.  
  4709.    firstweekday = JulianWeekday(1,1,year);
  4710.    days = (JulianDayDiff(1,1,year,day,month,year) + (long)firstweekday -1) / 7;
  4711.    if (firstweekday > Thursday)
  4712.      {if (days == 0)
  4713.         days = JulianWeek(31,12,year-1);
  4714.       else
  4715.         if ((firstweekday == Sunday) && JulianLeapYear(year) && (month == 12) && (day == 31))
  4716.           days = 1;
  4717.       return((unsigned short)days);
  4718.      }
  4719.    else
  4720.      {if (!JulianDaySmaller(day,month,year,29,12,year))
  4721.         {firstweekday = JulianWeekday(day,12,year);
  4722.          switch (day)
  4723.            {case 31 : if (firstweekday == Wednesday)
  4724.                         days = 0;
  4725.             case 30 : if (firstweekday == Tuesday)
  4726.                         days = 0;
  4727.             case 29 : if (firstweekday == Monday)
  4728.                         days = 0;
  4729.                       break;
  4730.             default : ;
  4731.            }
  4732.         }
  4733.       return((unsigned short)(days +1));
  4734.      }
  4735.  }
  4736.  
  4737.  
  4738.  #ifdef __MakeLib
  4739.    unsigned short __saveds __asm GregorianWeek(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  4740.  #else
  4741.    unsigned short GregorianWeek(const unsigned short day, const unsigned short month, const int year)
  4742.  #endif
  4743.  
  4744. /*
  4745. ******* Date/GregorianWeek **************************************************
  4746. *
  4747. *   NAME
  4748. *    GregorianWeek -- Gets the weeknumber of a specified date. (V33)
  4749. *
  4750. *   SYNOPSIS
  4751. *    weeknr = GregorianWeek(day,month,year);
  4752. *      d0            d0   d1   d2
  4753. *
  4754. *    unsigned short GregorianWeek(const unsigned short day,
  4755. *        const unsigned short month, const int year);
  4756. *
  4757. *   FUNCTION
  4758. *    GregorianWeek gets the weeknumber for a specified date.
  4759. *
  4760. *   INPUTS
  4761. *    day   - day of the date
  4762. *    month - month of the date
  4763. *    year  - year of the date
  4764. *
  4765. *   RESULT
  4766. *    week - This is the number of the week the specified date lies in.
  4767. *        If the first day in a new year is a Friday, Saturday or
  4768. *        Sunday, this would be the last week of the last year!
  4769. *        If the 29.12. is a Monday, the 30.12. is a Monday or a Tuesday,
  4770. *        the 31.12. is a Monday, Tuesday or a Wednesday this is the
  4771. *        first week of the next year!
  4772. *
  4773. *   EXAMPLE
  4774. *    ...
  4775. *    weeknr = GregorianWeek(4,10,1582);
  4776. *    ...
  4777. *
  4778. *   NOTES
  4779. *    It is better only to use this function for years from 0 to 3000!
  4780. *
  4781. *   BUGS
  4782. *    For years < 0 errors could occur.
  4783. *
  4784. *   SEE ALSO
  4785. *    JulianWeek(),HeisWeek(),GregorianWeekday(),GregorianDayDiff()
  4786. *
  4787. *****************************************************************************
  4788. *
  4789. *
  4790. */
  4791.  
  4792.  {long days;
  4793.   Weekdays firstweekday;
  4794.  
  4795.    firstweekday = GregorianWeekday(1,1,year);
  4796.    days = (GregorianDayDiff(1,1,year,day,month,year) + (long)firstweekday -1) / 7;
  4797.    if (firstweekday > Thursday)
  4798.      {if (days == 0)
  4799.         days = GregorianWeek(31,12,year-1);
  4800.       else
  4801.         if ((firstweekday == Sunday) && GregorianLeapYear(year) && (month == 12) && (day == 31))
  4802.           days = 1;
  4803.       return((unsigned short)days);
  4804.      }
  4805.    else
  4806.      {if (!GregorianDaySmaller(day,month,year,29,12,year))
  4807.         {firstweekday = GregorianWeekday(day,12,year);
  4808.          switch (day)
  4809.            {case 31 : if (firstweekday == Wednesday)
  4810.                         days = 0;
  4811.             case 30 : if (firstweekday == Tuesday)
  4812.                         days = 0;
  4813.             case 29 : if (firstweekday == Monday)
  4814.                         days = 0;
  4815.                       break;
  4816.             default : ;
  4817.            }
  4818.         }
  4819.       return((unsigned short)(days +1));
  4820.      }
  4821.  }
  4822.  
  4823.  
  4824.  #ifdef __MakeLib
  4825.    unsigned short __saveds __asm HeisWeek(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  4826.  #else
  4827.    unsigned short HeisWeek(const unsigned short day, const unsigned short month, const int year)
  4828.  #endif
  4829.  
  4830. /*
  4831. ******* Date/HeisWeek *******************************************************
  4832. *
  4833. *   NAME
  4834. *    HeisWeek -- Gets the weeknumber of a specified date. (V33)
  4835. *
  4836. *   SYNOPSIS
  4837. *    weeknr = HeisWeek(day,month,year);
  4838. *      d0           d0  d1    d2
  4839. *
  4840. *    unsigned short HeisWeek(const unsigned short day,
  4841. *        const unsigned short month, const int year);
  4842. *
  4843. *   FUNCTION
  4844. *    HeisWeek gets the weeknumber for a specified date.
  4845. *
  4846. *   INPUTS
  4847. *    day   - day of the date
  4848. *    month - month of the date
  4849. *    year  - year of the date
  4850. *
  4851. *   RESULT
  4852. *    week - This is the number of the week the specified date lies in.
  4853. *        If the first day in a new year is a Friday, Saturday or
  4854. *        Sunday, this would be the last week of the last year!
  4855. *        If the 29.12. is a Monday, the 30.12. is a Monday or a Tuesday,
  4856. *        the 31.12. is a Monday, Tuesday or a Wednesday this is the
  4857. *        first week of the next year!
  4858. *
  4859. *   EXAMPLE
  4860. *    ...
  4861. *    weeknr = HeisWeek(4,10,1582);
  4862. *    ...
  4863. *
  4864. *   NOTES
  4865. *    It is better only to use this function for years from 0 to 8000!
  4866. *
  4867. *   BUGS
  4868. *    For years < 0 errors could occur.
  4869. *
  4870. *   SEE ALSO
  4871. *    JulianWeek(),GregorianWeek(),HeisWeekday(),HeisDayDiff()
  4872. *
  4873. *****************************************************************************
  4874. *
  4875. *
  4876. */
  4877.  
  4878.  {long days;
  4879.   Weekdays firstweekday;
  4880.  
  4881.    firstweekday = HeisWeekday(1,1,year);
  4882.    days = (HeisDayDiff(1,1,year,day,month,year) + (long)firstweekday -1) / 7;
  4883.    if (firstweekday > Thursday)
  4884.      {if (days == 0)
  4885.         days = HeisWeek(31,12,year-1);
  4886.       else
  4887.         if ((firstweekday == Sunday) && HeisLeapYear(year) && (month == 12) && (day == 31))
  4888.           days = 1;
  4889.       return((unsigned short)days);
  4890.      }
  4891.    else
  4892.      {if (!HeisDaySmaller(day,month,year,29,12,year))
  4893.         {firstweekday = HeisWeekday(day,12,year);
  4894.          switch (day)
  4895.            {case 31 : if (firstweekday == Wednesday)
  4896.                         days = 0;
  4897.             case 30 : if (firstweekday == Tuesday)
  4898.                         days = 0;
  4899.             case 29 : if (firstweekday == Monday)
  4900.                         days = 0;
  4901.                       break;
  4902.             default : ;
  4903.            }
  4904.         }
  4905.       return((unsigned short)(days +1));
  4906.      }
  4907.  }
  4908.  
  4909.  /* ----------------------------------------------------------------------- */
  4910.  
  4911.  #ifdef __MakeLib
  4912.    unsigned short __saveds __asm WeekdayText(register __d0 Weekdays wday, register __a0 char *wtext, register __d1 Languages lang)
  4913.  #else
  4914.    unsigned short WeekdayText(Weekdays wday, char *wtext, Languages lang)
  4915.  #endif
  4916.  
  4917. /*
  4918. ******* Date/WeekdayText ****************************************************
  4919. *
  4920. *   NAME
  4921. *    WeekdayText -- Get the weekday as text string. (V33.091)
  4922. *
  4923. *   SYNOPSIS
  4924. *    maxlen = WeekdayText(wday,wtext,lang);
  4925. *      d0                  d0   a0    d1
  4926. *
  4927. *    unsigned short WeekdayText(Weekdays wday, char *wtext,
  4928. *        Languages lang);
  4929. *
  4930. *   FUNCTION
  4931. *    This function gets the text string for the weekday-number.
  4932. *
  4933. *   INPUTS
  4934. *    wday  - Weekday to transform into a string.
  4935. *    wtext - Pointer to a string to fill in the weekday-text.
  4936. *    lang  - Language for witch you want the weekday-text.
  4937. *
  4938. *   RESULT
  4939. *    maxlen - Maximum possible length for the weekday-string, this should
  4940. *        help you if you want to justify the string right or if you
  4941. *        want to center it!
  4942. *        0 indicates an error!
  4943. *
  4944. *   EXAMPLE
  4945. *    ...
  4946. *    char wtxt[20];
  4947. *    ...
  4948. *    maxlen = WeekdayText(Monday,&wtxt,English);
  4949. *    ...
  4950. *
  4951. *   NOTES
  4952. *    Available languages:
  4953. *    Locale   : This is an Amiga >= OS2.1 only feature, for <= OS2.0
  4954. *               and other systems it will return english text!
  4955. *    English
  4956. *    Deutsch
  4957. *    français : For non ISO8859_Latin1-systems this is called francais!
  4958. *    español  : For non ISO8859_Latin1-systems this is called espanol!
  4959. *
  4960. *   BUGS
  4961. *    In this version there is no check, if there is enough space in
  4962. *    wtext!
  4963. *
  4964. *   SEE ALSO
  4965. *    MonthText(),WeekdayShortText(),MonthShortText()
  4966. *
  4967. *****************************************************************************
  4968. *
  4969. *
  4970. */
  4971.  
  4972.  {
  4973.   unsigned short len=0;
  4974.   const unsigned short WEEKDAYMAXLEN[5]   = {0,9,10,8,9};
  4975.   const char           WEEKDAYS[5][8][11] = {{"","","","","","","",""},
  4976.                                              {"","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},
  4977.                                              {"","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag","Sonntag"},
  4978.                                              {"","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"},
  4979.                                              {"","lunes","martes",
  4980.                                               #ifdef _ISO8859_Latin1
  4981.                                                 "miércoles"
  4982.                                               #else
  4983.                                                 "mie'rcoles"
  4984.                                               #endif
  4985.                                               ,"jueves","viernes",
  4986.                                               #ifdef _ISO8859_Latin1
  4987.                                                 "sábado"
  4988.                                               #else
  4989.                                                 "sa'bado"
  4990.                                               #endif
  4991.                                               ,"domingo"}};
  4992.  
  4993.   if (wtext != NULL)
  4994.    {
  4995.     wtext[0] = '\0';
  4996.     switch (lang)
  4997.      {
  4998.       case Locale :
  4999.       #ifdef _AMIGA
  5000.                     if (locale != NULL)
  5001.                      {
  5002.                       len = wlen;
  5003.                       switch (wday)
  5004.                        {
  5005.                         case Sunday : strcpy(wtext,GetLocaleStr(locale,DAY_1));
  5006.                                       break;
  5007.                         case dayerr : len = 0;
  5008.                                       break;
  5009.                         default     : strcpy(wtext,GetLocaleStr(locale,DAYS[(unsigned short)wday]));
  5010.                        }
  5011.                       break;
  5012.                      }
  5013.       #else
  5014.                     lang = English;
  5015.       #endif
  5016.       default     :  len = WEEKDAYMAXLEN[(unsigned short)lang];
  5017.                      if (wday == dayerr)
  5018.                        len = 0;
  5019.                      else
  5020.                        strcpy(wtext,WEEKDAYS[(unsigned short)lang][(unsigned short)wday]);
  5021.      }
  5022.    }
  5023.   return(len);
  5024.  }
  5025.  
  5026.  
  5027.  #ifdef __MakeLib
  5028.    unsigned short __saveds __asm MonthText(register __d0 unsigned short month, register __a0 char *mtext, register __d1 Languages lang)
  5029.  #else
  5030.    unsigned short MonthText(unsigned short month, char *mtext, Languages lang)
  5031.  #endif
  5032.  
  5033. /*
  5034. ******* Date/MonthText ******************************************************
  5035. *
  5036. *   NAME
  5037. *    MonthText -- Get the month as text string. (V33.091)
  5038. *
  5039. *   SYNOPSIS
  5040. *    maxlen = MonthText(month,mtext,lang);
  5041. *     d0                 d0   a0    d1
  5042. *
  5043. *    unsigned short MonthText(unsigned short month, char *mtext,
  5044. *        Languages lang);
  5045. *
  5046. *   FUNCTION
  5047. *    This function gets the text string for the month-number.
  5048. *
  5049. *   INPUTS
  5050. *    month - Month to transform into a string.
  5051. *    mtext - Pointer to a string to fill in the month-text.
  5052. *    lang  - Language for which you want the month-text.
  5053. *
  5054. *   RESULT
  5055. *    maxlen - Maximum possible length for the month-string, this should
  5056. *        help you if you want to justify the string right or if you
  5057. *        want to center it!
  5058. *        0 indicates an error!
  5059. *
  5060. *   EXAMPLE
  5061. *    ...
  5062. *    char mtxt[20];
  5063. *    ...
  5064. *    maxlen = MonthText(12,&mtxt,English);
  5065. *    ...
  5066. *
  5067. *   NOTES
  5068. *    Available languages:
  5069. *    Locale   : This is an Amiga >= OS2.1 only feature, for <= OS2.0
  5070. *               and other systems it will return english text!
  5071. *    English
  5072. *    Deutsch
  5073. *    français : For non ISO8859_Latin1-systems this is called francais!
  5074. *    español  : For non ISO8859_Latin1-systems this is called espanol!
  5075. *
  5076. *   BUGS
  5077. *    In this version there is no check, if there is enough space in
  5078. *    wtext!
  5079. *
  5080. *   SEE ALSO
  5081. *    WeekdayText(),WeekdayShortText(),MonthShortText()
  5082. *
  5083. *****************************************************************************
  5084. *
  5085. *
  5086. */
  5087.  
  5088.  {
  5089.   unsigned short len=0;
  5090.   const unsigned short MONTHMAXLEN[5]    = {0,9,9,9,10};
  5091.   const char           MONTHS[5][13][11] = {{"","","","","","","","","","","","",""},
  5092.                                             {"","January","February","March","April","May","June","July","August","September","October","November","December"},
  5093.                                             {"","Januar","Februar",
  5094.                                              #ifdef _ISO8859_Latin1
  5095.                                                "März"
  5096.                                              #else
  5097.                                                "Maerz"
  5098.                                              #endif
  5099.                                              ,"April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"},
  5100.                                             {"","Janvier",
  5101.                                              #ifdef _ISO8859_Latin1
  5102.                                                "Février"
  5103.                                              #else
  5104.                                                "Fe'vrier"
  5105.                                              #endif
  5106.                                              ,"Mars","Avril","Mai","Juin","Juillet",
  5107.                                              #ifdef _ISO8859_Latin1
  5108.                                                "Août"
  5109.                                              #else
  5110.                                                "Aou^t"
  5111.                                              #endif
  5112.                                              ,"Septembre","Octobre","Novembre",
  5113.                                              #ifdef _ISO8859_Latin1
  5114.                                                "Décembre"
  5115.                                              #else
  5116.                                                "De'cembre"
  5117.                                              #endif
  5118.                                             },
  5119.                                             {"","enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre"}};
  5120.  
  5121.   if (mtext != NULL)
  5122.    {
  5123.     mtext[0] = '\0';
  5124.     if (!((month > 0) && (month < 13)))
  5125.       return(0);
  5126.     switch (lang)
  5127.      {
  5128.       case Locale  :
  5129.       #ifdef _AMIGA
  5130.                      if (locale != NULL)
  5131.                       {
  5132.                        len = mlen;
  5133.                        strcpy(mtext,GetLocaleStr(locale,MONS[month-1]));
  5134.                        break;
  5135.                       }
  5136.       #else
  5137.                      lang = English;
  5138.       #endif
  5139.       default      : len = MONTHMAXLEN[(unsigned short)lang];
  5140.                      strcpy(mtext,MONTHS[(unsigned short)lang][month]);
  5141.      }
  5142.    }
  5143.   return(len);
  5144.  }
  5145.  
  5146.  /* ----------------------------------------------------------------------- */
  5147.  
  5148.  #ifdef __MakeLib
  5149.    unsigned short __saveds __asm WeekdayShortText(register __d0 Weekdays wday, register __a0 char *wtext, register __d1 Languages lang)
  5150.  #else
  5151.    unsigned short WeekdayShortText(Weekdays wday, char *wtext, Languages lang)
  5152.  #endif
  5153.  
  5154. /*
  5155. ******* Date/WeekdayShortText ***********************************************
  5156. *
  5157. *   NAME
  5158. *    WeekdayShortText -- Get the weekday as short text string. (V33.092)
  5159. *
  5160. *   SYNOPSIS
  5161. *    maxlen = WeekdayShortText(wday,wtext,lang);
  5162. *    d0                         d0   a0    d1
  5163. *
  5164. *    unsigned short WeekdayShortText(Weekdays wday, char *wtext,
  5165. *        Languages lang);
  5166. *
  5167. *   FUNCTION
  5168. *    This function gets the short text string for the weekday-number.
  5169. *
  5170. *   INPUTS
  5171. *    wday  - Weekday to transform into a string.
  5172. *    wtext - Pointer to a string to fill in the short weekday-text.
  5173. *    lang  - Language for witch you want the short weekday-text.
  5174. *
  5175. *   RESULT
  5176. *    maxlen - Maximum possible length for the weekday-string, this should
  5177. *        help you if you want to justify the string right or if you
  5178. *        want to center it! (Normal it's two or three!)
  5179. *        0 indicates an error!
  5180. *
  5181. *   EXAMPLE
  5182. *    ...
  5183. *    char wtxt[3];
  5184. *    ...
  5185. *    maxlen = WeekdayShortText(Monday,&wtxt,English);
  5186. *    ...
  5187. *
  5188. *   NOTES
  5189. *    Available languages:
  5190. *    Locale   : This is an Amiga >= OS2.1 only feature, for <= OS2.0
  5191. *               and other systems it will return english text!
  5192. *    English
  5193. *    Deutsch
  5194. *    français : For non ISO8859_Latin1-systems this is called francais!
  5195. *    español  : For non ISO8859_Latin1-systems this is called espanol!
  5196. *
  5197. *   BUGS
  5198. *    In this version there is no check, if there is enough space in
  5199. *    wtext!
  5200. *
  5201. *   SEE ALSO
  5202. *    WeekdayText(),MonthText(),MonthShortText()
  5203. *
  5204. *****************************************************************************
  5205. *
  5206. *
  5207. */
  5208.  
  5209.  {
  5210.   unsigned short len=0;
  5211.   const unsigned short WEEKDAYMAXLEN[5]  = {0,3,2,3,3};
  5212.   const char           WEEKDAYS[5][8][4] = {{"","","","","","","",""},
  5213.                                             {"","Mon","Tue","Wed","Thu","Fri","Sat","Sun"},
  5214.                                             {"","Mo","Di","Mi","Do","Fr","Sa","So"},
  5215.                                             {"","Lun","Mar","Mer","Jeu","Ven","Sam","Dim"},
  5216.                                             {"","lun","mar","mie","jue","vie","sab","dom"}};
  5217.  
  5218.   if (wtext != NULL)
  5219.    {
  5220.     wtext[0] = '\0';
  5221.     switch (lang)
  5222.      {
  5223.       case Locale :
  5224.       #ifdef _AMIGA
  5225.                     if (locale != NULL)
  5226.                      {
  5227.                       len = abwlen;
  5228.                       switch (wday)
  5229.                        {
  5230.                         case Sunday : strcpy(wtext,GetLocaleStr(locale,ABDAY_1));
  5231.                                       break;
  5232.                         case dayerr : len = 0;
  5233.                                       break;
  5234.                         default     : strcpy(wtext,GetLocaleStr(locale,ABDAYS[(unsigned short)wday]));
  5235.                        }
  5236.                       break;
  5237.                      }
  5238.       #else
  5239.                     lang = English;
  5240.       #endif
  5241.       default     :  len = WEEKDAYMAXLEN[(unsigned short)lang];
  5242.                      if (wday == dayerr)
  5243.                        len = 0;
  5244.                      else
  5245.                        strcpy(wtext,WEEKDAYS[(unsigned short)lang][(unsigned short)wday]);
  5246.      }
  5247.    }
  5248.   return(len);
  5249.  }
  5250.  
  5251.  
  5252.  #ifdef __MakeLib
  5253.    unsigned short __saveds __asm MonthShortText(register __d0 unsigned short month, register __a0 char *mtext, register __d1 Languages lang)
  5254.  #else
  5255.    unsigned short MonthShortText(unsigned short month, char *mtext, Languages lang)
  5256.  #endif
  5257.  
  5258. /*
  5259. ******* Date/MonthShortText *************************************************
  5260. *
  5261. *   NAME
  5262. *    MonthShortText -- Get the month as short text string. (V33.092)
  5263. *
  5264. *   SYNOPSIS
  5265. *    maxlen = MonthShortText(month,mtext,lang);
  5266. *     d0                       d0   a0    d1
  5267. *
  5268. *    unsigned short MonthShortText(unsigned short month, char *mtext,
  5269. *        Languages lang);
  5270. *
  5271. *   FUNCTION
  5272. *    This function gets the short text string for the month-number.
  5273. *
  5274. *   INPUTS
  5275. *    month - Month to transform into a string.
  5276. *    mtext - Pointer to a string to fill in the short month-text.
  5277. *    lang  - Language for which you want the short month-text.
  5278. *
  5279. *   RESULT
  5280. *    maxlen - Maximum possible length for the short month-string, this
  5281. *        should help you if you want to justify the string right or if
  5282. *        you want to center it (Normal is three!).
  5283. *        0 indicates an error!
  5284. *
  5285. *   EXAMPLE
  5286. *    ...
  5287. *    char mtxt[4];
  5288. *    ...
  5289. *    maxlen = MonthShortText(12,&mtxt,English);
  5290. *    ...
  5291. *
  5292. *   NOTES
  5293. *    Available languages:
  5294. *    Locale   : This is an Amiga >= OS2.1 only feature, for <= OS2.0
  5295. *               and other systems it will return english text!
  5296. *    English
  5297. *    Deutsch
  5298. *    français : For non ISO8859_Latin1-systems this is called francais!
  5299. *    español  : For non ISO8859_Latin1-systems this is called espanol!
  5300. *
  5301. *   BUGS
  5302. *    In this version there is no check, if there is enough space in
  5303. *    wtext!
  5304. *
  5305. *   SEE ALSO
  5306. *    WeekdayText(),WeekdayShortText(),MonthText()
  5307. *
  5308. *****************************************************************************
  5309. *
  5310. *
  5311. */
  5312.  
  5313.  {
  5314.   unsigned short len=0;
  5315.   const unsigned short MONTHMAXLEN[5]   = {0,3,3,
  5316.                                                  #ifdef _ISO8859_Latin1
  5317.                                                    4
  5318.                                                  #else
  5319.                                                    5
  5320.                                                  #endif
  5321.                                                   ,3};
  5322.   const char           MONTHS[5][13][6] = {{"","","","","","","","","","","","",""},
  5323.                                            {"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},
  5324.                                            {"","Jan","Feb",
  5325.                                             #ifdef _ISO8859_Latin1
  5326.                                               "Mär"
  5327.                                             #else
  5328.                                               "Maer"
  5329.                                             #endif
  5330.                                             ,"Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"},
  5331.                                            {"","Jan",
  5332.                                             #ifdef _ISO8859_Latin1
  5333.                                               "Fév"
  5334.                                             #else
  5335.                                               "Fe'v"
  5336.                                             #endif
  5337.                                             ,"Mars","Avr","Mai","Juin","Juil",
  5338.                                             #ifdef _ISO8859_Latin1
  5339.                                               "Août"
  5340.                                             #else
  5341.                                               "Aou^t"
  5342.                                             #endif
  5343.                                             ,"Sep","Oct","Nov",
  5344.                                             #ifdef _ISO8859_Latin1
  5345.                                               "Déc"
  5346.                                             #else
  5347.                                               "De'c"
  5348.                                             #endif
  5349.                                            },
  5350.                                            {"","ene","feb","mar","abr","may","jun","jul","ago","sep","oct","nov","dic"}};
  5351.  
  5352.   if (mtext != NULL)
  5353.    {
  5354.     mtext[0] = '\0';
  5355.     if (!((month > 0) && (month < 13)))
  5356.       return(0);
  5357.     switch (lang)
  5358.      {
  5359.       case Locale  :
  5360.       #ifdef _AMIGA
  5361.                      if (locale != NULL)
  5362.                       {
  5363.                        len = abmlen;
  5364.                        strcpy(mtext,GetLocaleStr(locale,ABMONS[month-1]));
  5365.                        break;
  5366.                       }
  5367.       #else
  5368.                      lang = English;
  5369.       #endif
  5370.       default      : len = MONTHMAXLEN[(unsigned short)lang];
  5371.                      strcpy(mtext,MONTHS[(unsigned short)lang][month]);
  5372.      }
  5373.    }
  5374.   return(len);
  5375.  }
  5376.  
  5377.  /* ----------------------------------------------------------------------- */
  5378.  
  5379.  #ifdef __MakeLib
  5380.    void __saveds __asm JDToJulian(register __d0 const unsigned long jd, register __a0 unsigned short *day, register __a1 unsigned short *month, register __a2 int *year)
  5381.  #else
  5382.    void JDToJulian(const unsigned long jd, unsigned short *day, unsigned short *month, int *year)
  5383.  #endif
  5384.  
  5385. /*
  5386. ******* Date/JDToJulian *****************************************************
  5387. *
  5388. *   NAME
  5389. *    JDToJulian -- Returns the Julian date for a JD. (V33.095)
  5390. *
  5391. *   SYNOPSIS
  5392. *    JDToJulian(jd,day,month,year);
  5393. *           d0 a0   a1    a2
  5394. *
  5395. *    void JDToJulian(const unsigned long jd, unsigned short *day,
  5396. *        unsigned short *month, int *year);
  5397. *
  5398. *   FUNCTION
  5399. *    Returns the Julian date for a JD.
  5400. *
  5401. *   INPUTS
  5402. *    jd    - This is the given JD.
  5403. *
  5404. *   RESULT
  5405. *    day    - Day of the date.
  5406. *    month    - Month of the date.
  5407. *    year    - Year of the date.
  5408. *
  5409. *   EXAMPLE
  5410. *    ...
  5411. *    JDToJulian(2299160,&day,&month,&year);
  5412. *    ...
  5413. *
  5414. *   NOTES
  5415. *    It is better to use this function only from 1718867 to 2299160!
  5416. *
  5417. *   BUGS
  5418. *    unknown.
  5419. *
  5420. *   SEE ALSO
  5421. *    JDToGregorian(),JDToHeis()
  5422. *
  5423. *****************************************************************************
  5424. *
  5425. *
  5426. */
  5427.  
  5428.  {
  5429.   unsigned long a;
  5430.   unsigned int  b,c;
  5431.   unsigned short d;
  5432.  
  5433.   a = jd+1524;
  5434.   b = floor((a-122.1)/365.25);
  5435.   c = a-floor(365.25*b);
  5436.   d = floor(c/30.6001);
  5437.   *day = c-floor(30.6001*d);
  5438.   *month = d<14 ? d-1 : d-13 ;
  5439.   *year = (*month)>2 ? b-4716 : b-4715 ;
  5440.   if ((*year) < 1)
  5441.     (*year)--;
  5442.  }
  5443.  
  5444.  
  5445.  #ifdef __MakeLib
  5446.    void __saveds __asm JDToGregorian(register __d0 const unsigned long jd, register __a0 unsigned short *day, register __a1 unsigned short *month, register __a2 int *year)
  5447.  #else
  5448.    void JDToGregorian(const unsigned long jd, unsigned short *day, unsigned short *month, int *year)
  5449.  #endif
  5450.  
  5451. /*
  5452. ******* Date/JDToGregorian **************************************************
  5453. *
  5454. *   NAME
  5455. *    JDToGregorian -- Returns the Gregorian date for a JD. (V33.095)
  5456. *
  5457. *   SYNOPSIS
  5458. *    JDToGregorian(jd,day,month,year);
  5459. *              d0 a0   a1    a2
  5460. *
  5461. *    void JDToGregorian(const unsigned long jd, unsigned short *day,
  5462. *        unsigned short *month, int *year);
  5463. *
  5464. *   FUNCTION
  5465. *    Returns the Gregorian date for a JD.
  5466. *
  5467. *   INPUTS
  5468. *    jd    - This is the given JD.
  5469. *
  5470. *   RESULT
  5471. *    day    - Day of the date.
  5472. *    month    - Month of the date.
  5473. *    year    - Year of the date.
  5474. *
  5475. *   EXAMPLE
  5476. *    ...
  5477. *    JDToGregorian(2299161,&day,&month,&year);
  5478. *    ...
  5479. *
  5480. *   NOTES
  5481. *    It is better to use this function only from 1718867 to 2889835!
  5482. *
  5483. *   BUGS
  5484. *    unknown.
  5485. *
  5486. *   SEE ALSO
  5487. *    JDToJulian(),JDToHeis()
  5488. *
  5489. *****************************************************************************
  5490. *
  5491. *
  5492. */
  5493.  
  5494.  {
  5495.   unsigned long a;
  5496.   unsigned int  b,c;
  5497.   unsigned short d,e;
  5498.  
  5499.   if (jd < 2299161)
  5500.    {
  5501.     JDToJulian(jd,day,month,year);
  5502.    }
  5503.   else
  5504.    {
  5505.     e = floor((jd-1867216.25)/36524.25);
  5506.     a = jd+1524+1+ e - e/4;
  5507.     b = floor((a-122.1)/365.25);
  5508.     c = a-floor(365.25*b);
  5509.     d = floor(c/30.6001);
  5510.     *day = c-floor(30.6001*d);
  5511.     *month = d<14 ? d-1 : d-13 ;
  5512.     *year = (*month)>2 ? b-4716 : b-4715 ;
  5513.     if ((*year) < 1)
  5514.       (*year)--;
  5515.    }
  5516.  }
  5517.  
  5518.  
  5519.  #ifdef __MakeLib
  5520.    void __saveds __asm JDToHeis(register __d0 const unsigned long jd, register __a0 unsigned short *day, register __a1 unsigned short *month, register __a2 int *year)
  5521.  #else
  5522.    void JDToHeis(const unsigned long jd, unsigned short *day, unsigned short *month, int *year)
  5523.  #endif
  5524.  
  5525. /*
  5526. ******* Date/JDToHeis *******************************************************
  5527. *
  5528. *   NAME
  5529. *    JDToHeis -- Returns the Heis date for a JD. (V33.095)
  5530. *
  5531. *   SYNOPSIS
  5532. *    JDToHeis(jd,day,month,year);
  5533. *         d0 a0   a1    a2
  5534. *
  5535. *    void JDToHeis(const unsigned long jd, unsigned short *day,
  5536. *        unsigned short *month, int *year);
  5537. *
  5538. *   FUNCTION
  5539. *    Returns the Heis date for a JD.
  5540. *
  5541. *   INPUTS
  5542. *    jd    - This is the given JD.
  5543. *
  5544. *   RESULT
  5545. *    day    - Day of the date.
  5546. *    month    - Month of the date.
  5547. *    year    - Year of the date.
  5548. *
  5549. *   EXAMPLE
  5550. *    ...
  5551. *    JDToHeis(2299161,&day,&month,&year);
  5552. *    ...
  5553. *
  5554. *   NOTES
  5555. *    In the moment this is only a dummy to JDToGregorian, so:
  5556. *    It is better to use this function only from 1718867 to 2889835!
  5557. *
  5558. *   BUGS
  5559. *    unknown.
  5560. *
  5561. *   SEE ALSO
  5562. *    JDToJulian(), JDToGregorian()
  5563. *
  5564. *****************************************************************************
  5565. *
  5566. *
  5567. */
  5568.  
  5569.  {
  5570.   JDToGregorian(jd,day,month,year);
  5571.  }
  5572.  
  5573.  /* ----------------------------------------------------------------------- */
  5574.  
  5575.  static unsigned long GregorianMoonPhaseHelp(const unsigned short day, const unsigned short month, const int year, const MoonPhases phase)
  5576.  
  5577. /*
  5578. *****i* Date/GregorianMoonPhaseHelp *****************************************
  5579. *
  5580. *   NAME
  5581. *    GregorianMoonPhaseHelp -- Searches for the next moon phase (V33.099)
  5582. *
  5583. *   SYNOPSIS
  5584. *    jd = GregorianMoonPhaseHelp(day,month,year,phase);
  5585. *    d0                     d0   d1    d2   d3
  5586. *
  5587. *    unsigned long GregorianMoonPhaseHelp(const unsigned short day,
  5588. *        const unsigned short month, const int year,
  5589. *        const MoonPhases phase);
  5590. *
  5591. *   FUNCTION
  5592. *    Returns the next moon phase you are searching for after
  5593. *    an specified date.
  5594. *
  5595. *   INPUTS
  5596. *    day   - Start day for the search.
  5597. *    month - Start month for the search.
  5598. *    year  - Start year for the search.
  5599. *    phase - The moon phase you want to know.
  5600. *
  5601. *   RESULT
  5602. *    jd - The day (as JD) on wich the moon phase was found.
  5603. *
  5604. *   EXAMPLE
  5605. *    ...
  5606. *    jd = GregorianMoonPhaseHelp(18,9,1994,FullMoon);
  5607. *    JDToGregorian(jd,&day,&month,&year);
  5608. *    ...
  5609. *
  5610. *   NOTES
  5611. *    The range of this function is unknown for me!
  5612. *    So use it only from 1583 to 2500.
  5613. *    This is only a experimental version!
  5614. *
  5615. *   BUGS
  5616. *    unknown.
  5617. *
  5618. *   SEE ALSO
  5619. *    GregorianMoonPhase()
  5620. *
  5621. *****************************************************************************
  5622. *
  5623. *
  5624. */
  5625.  
  5626.  {
  5627.   float y;
  5628.   double k,t,t2,jd;
  5629.  
  5630.   y = year+(GregorianDayDiff(1,1,year,day,month,year)/(double)GregorianYearDays(year));
  5631.   k = floor((y-2000)*12.3685);
  5632.   switch (phase)
  5633.    {
  5634.     case NewMoon      : /* k += 0; */
  5635.                         break;
  5636.     case FirstQuarter : k += 0.25;
  5637.                         break;
  5638.     case FullMoon     : k += 0.5;
  5639.                         break;
  5640.     case LastQuarter  : k += 0.75;
  5641.                         /* break; */
  5642.    }
  5643.   t = k/1236.85;
  5644.   t2 = t*t;
  5645.   jd = 2451550.09765+29.530588853*k+0.0001337*t2-0.00000015*t2*t+0.00000000073*t2*t2;
  5646.   return((unsigned long)jd);
  5647.  }
  5648.  
  5649.  
  5650.  #ifdef __MakeLib
  5651.    unsigned long __saveds __asm GregorianMoonPhase(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year, register __d3 const MoonPhases phase)
  5652.  #else
  5653.    unsigned long GregorianMoonPhase(const unsigned short day, const unsigned short month, const int year, const MoonPhases phase)
  5654.  #endif
  5655.  
  5656. /*
  5657. ******* Date/GregorianMoonPhase *********************************************
  5658. *
  5659. *   NAME
  5660. *    GregorianMoonPhase -- Searches for the next moon phase (V33.098)
  5661. *
  5662. *   SYNOPSIS
  5663. *    jd = GregorianMoonPhase(day,month,year,phase);
  5664. *    d0                d0   d1    d2   d3
  5665. *
  5666. *    unsigned long GregorianMoonPhase(const unsigned short day,
  5667. *        const unsigned short month, const int year,
  5668. *        const MoonPhases phase);
  5669. *
  5670. *   FUNCTION
  5671. *    Returns the next moon phase you are searching for after
  5672. *    an specified date.
  5673. *
  5674. *   INPUTS
  5675. *    day   - Start day for the search.
  5676. *    month - Start month for the search.
  5677. *    year  - Start year for the search.
  5678. *    phase - The moon phase you want to know.
  5679. *
  5680. *   RESULT
  5681. *    jd - The day (as JD) on wich the moon phase was found.
  5682. *
  5683. *   EXAMPLE
  5684. *    ...
  5685. *    jd = GregorianMoonPhase(18,9,1994,FullMoon);
  5686. *    JDToGregorian(jd,&day,&month,&year);
  5687. *    ...
  5688. *
  5689. *   NOTES
  5690. *    The range of this function is unknown for me!
  5691. *    So use it only from 1583 to 2500.
  5692. *    This is only a experimental version!
  5693. *
  5694. *   BUGS
  5695. *    unknown.
  5696. *
  5697. *   SEE ALSO
  5698. *    MoonMonthAge()
  5699. *
  5700. *****************************************************************************
  5701. *
  5702. *
  5703. */
  5704.  
  5705.  {
  5706.   unsigned long jd;
  5707.  
  5708.   jd = GregorianMoonPhaseHelp(day,month,year,phase);
  5709.   if (jd >= GregorianToJD(day,month,year))
  5710.    {
  5711.     return(jd);
  5712.    }
  5713.   else
  5714.    {
  5715.     unsigned short d,m;
  5716.     int y;
  5717.  
  5718.     GregorianDiffDate(day,month,year,25,&d,&m,&y);
  5719.     jd = GregorianMoonPhaseHelp(d,m,y,phase);
  5720.     return(jd);
  5721.    }
  5722.  }
  5723.  
  5724.  /* ----------------------------------------------------------------------- */
  5725.  
  5726.  #ifdef __MakeLib
  5727.    short __saveds __asm CompareTimes(register __d0 const unsigned short hour1, register __d1 const unsigned short min1, register __d2 const unsigned short sec1, register __d3 const unsigned short hour2, register __d4 const unsigned short min2, register __d5 const unsigned short sec2)
  5728.  #else
  5729.    short CompareTimes(const unsigned short hour1, const unsigned short min1, const unsigned short sec1, const unsigned short hour2, const unsigned short min2, const unsigned short sec2)
  5730.  #endif
  5731.  
  5732. /*
  5733. ******* Date/CompareTimes ***************************************************
  5734. *
  5735. *   NAME
  5736. *    CompareTimes -- Compares time1 with time2. (V33.100)
  5737. *
  5738. *   SYNOPSIS
  5739. *    compare = CompareTimes(hour1,min1,sec1,hour2,min2,sec2);
  5740. *      d0            d0    d1   d2   d3    d4   d5
  5741. *
  5742. *    short CompareTimes(const unsigned short hour1,
  5743. *        const unsigned short min1, const unsigned short sec1,
  5744. *        const unsigned short hour2, const unsigned short min2,
  5745. *        const unsigned short sec2);
  5746. *
  5747. *   FUNCTION
  5748. *    CompareTimes compares time1 with time2 (24h format only).
  5749. *
  5750. *   INPUTS
  5751. *    hour1 - Hour of the first time.
  5752. *    min1  - Minute of the first time.
  5753. *    sec1  - Second of the first time.
  5754. *    hour2 - Hour of the second time.
  5755. *    min2  - Minute of the second time.
  5756. *    sec2  - Second of the second time.
  5757. *
  5758. *   RESULT
  5759. *    compare - -1 : time1 < time2
  5760. *           0 : time1 = time2
  5761. *           1 : time1 > time2
  5762. *
  5763. *   EXAMPLE
  5764. *    ...
  5765. *    if (CompareTimes(13,10,0,9,0,0) == -1)
  5766. *      printf("<\n");
  5767. *    else
  5768. *      printf(">=\n");
  5769. *    ...
  5770. *
  5771. *   NOTES
  5772. *    This compares two times of 24h format!
  5773. *
  5774. *   BUGS
  5775. *    There is no check if the times are valid times!
  5776. *
  5777. *   SEE ALSO
  5778. *    CompareDates()
  5779. *
  5780. *****************************************************************************
  5781. *
  5782. *
  5783. */
  5784.  
  5785.  {
  5786.   if (hour1 < hour2)
  5787.     return(-1);
  5788.   else if (hour1 > hour2)
  5789.     return(1);
  5790.   else if (min1 < min2)
  5791.     return(-1);
  5792.   else if (min1 > min2)
  5793.     return(1);
  5794.   else if (sec1 < sec2)
  5795.     return(-1);
  5796.   else if (sec1 > sec2)
  5797.     return(1);
  5798.   else
  5799.     return(0);
  5800.  }
  5801.  
  5802.  /* ----------------------------------------------------------------------- */
  5803.  /* ----------------------------------------------------------------------- */
  5804.  
  5805.  static unsigned short maximum(unsigned short a, unsigned short b)
  5806.  
  5807. /*
  5808. *****i* Date/maximum ********************************************************
  5809. *
  5810. *   NAME
  5811. *    maximum -- Procedure to find the maximum of a and b (V33)
  5812. *
  5813. *   SYNOPSIS
  5814. *    max = maximum(a,b);
  5815. *
  5816. *    unsigned short maximum(unsigned short a, unsigned short b);
  5817. *
  5818. *   FUNCTION
  5819. *    Calculating the maximum of a and b.
  5820. *
  5821. *   INPUTS
  5822. *    a - First number.
  5823. *    b - Second number.
  5824. *
  5825. *   RESULT
  5826. *    max - The maximum of a and b.
  5827. *
  5828. *   EXAMPLE
  5829. *    ...
  5830. *    max = maximum(10,15); / * Should be 15 * /
  5831. *    ...
  5832. *
  5833. *   NOTES
  5834. *    None.
  5835. *
  5836. *   BUGS
  5837. *    none.
  5838. *
  5839. *   SEE ALSO
  5840. *
  5841. *
  5842. *****************************************************************************
  5843. *
  5844. *
  5845. */
  5846.  
  5847.  {
  5848.   if (a > b)
  5849.     return(a);
  5850.   else
  5851.     return(b);
  5852.  }
  5853.  
  5854.  /* ----------------------------------------------------------------------- */
  5855.  
  5856.  #ifdef __SASC_650
  5857.    #ifdef __MakeLib
  5858.      int __saveds __UserLibInit(struct Library *libbase)
  5859.    #else
  5860.      void _STI_600__DateInit(void)
  5861.    #endif
  5862.  #else
  5863.    void _DateInit(void)
  5864.  #endif
  5865.  
  5866. /*
  5867. ******* Date/_DateInit ******************************************************
  5868. *
  5869. *   NAME
  5870. *    _DateInit -- Procedure to initialize this module! (V33)
  5871. *
  5872. *   SYNOPSIS
  5873. *    _DateInit();
  5874. *
  5875. *    void _DateInit(void);
  5876. *
  5877. *   FUNCTION
  5878. *    Initialize this module, like the modulebody in Modula-II or Oberon-2
  5879. *
  5880. *   INPUTS
  5881. *    None.
  5882. *
  5883. *   RESULT
  5884. *    None.
  5885. *
  5886. *   EXAMPLE
  5887. *    ...
  5888. *    _DateInit();
  5889. *    ...
  5890. *
  5891. *   NOTES
  5892. *    This function is only needed/available if you do not compile this
  5893. *    with a SAS C Compiler (using Autoinitialization!)
  5894. *    If you are not using SASC - don't forget to init this module with
  5895. *    this function - or you will get into trouble!!!
  5896. *
  5897. *   BUGS
  5898. *    unknown.
  5899. *
  5900. *   SEE ALSO
  5901. *
  5902. *
  5903. *****************************************************************************
  5904. *
  5905. *
  5906. */
  5907.  
  5908.  {/* Dates of Gregorian reform in
  5909.      Rom:
  5910.        5.10.1582-14.10.1582
  5911.      Deutschland, Niederlande, Schweiz, Dänemark:
  5912.        18.02.1700-01.03.1700
  5913.      Großbritannien
  5914.        02.09.1752-14.09.1752
  5915.      Schweden
  5916.        17.02.1753-01.03.1753
  5917.      Rußland
  5918.        ? (oktober Revolution)
  5919.      Griechenland
  5920.        ??.??.1923-??.??.1923 */
  5921.   /* Bremen/Arbergen = 8° 55' 23" East, 53° 4' 8" North */
  5922.   #ifdef _AMIGA
  5923.     #ifndef __SASC_650
  5924.       LocaleBase = OpenLibrary("locale.library",0);
  5925.     #endif
  5926.     if (LocaleBase != NULL)
  5927.      {
  5928.       locale = OpenLocale(NULL);
  5929.       if (locale != NULL)
  5930.        {
  5931.         unsigned short i;
  5932.  
  5933.         wlen = strlen(GetLocaleStr(locale,DAY_1));
  5934.         abwlen = strlen(GetLocaleStr(locale,ABDAY_1));
  5935.         for (i=1;i<7;i++)
  5936.          {
  5937.           wlen = maximum(wlen,strlen(GetLocaleStr(locale,DAYS[i])));
  5938.           abwlen = maximum(abwlen,strlen(GetLocaleStr(locale,ABDAYS[i])));
  5939.          }
  5940.         mlen = strlen(GetLocaleStr(locale,MON_1));
  5941.         abmlen = strlen(GetLocaleStr(locale,ABMON_1));
  5942.         for (i=1;i<12;i++)
  5943.          {
  5944.           mlen = maximum(mlen,strlen(GetLocaleStr(locale,MONS[i])));
  5945.           abmlen = maximum(abmlen,strlen(GetLocaleStr(locale,ABMONS[i])));
  5946.          }
  5947.        }
  5948.      }
  5949.   #endif
  5950.   #ifdef __MakeLib
  5951.     return(0);
  5952.   #endif
  5953.  }
  5954.  
  5955.  
  5956.  #ifdef _SASC_650
  5957.    #ifdef __MakeLib
  5958.      void __saveds __UserLibCleanup(struct Library *libbase)
  5959.    #else
  5960.      void _STD_600__DateCleanup(void)
  5961.    #endif
  5962.  #else
  5963.    void _DateCleanup(void)
  5964.  #endif
  5965.  
  5966. /*
  5967. ******* Date/_DateCleanup ***************************************************
  5968. *
  5969. *   NAME
  5970. *    _DateCleanup -- Procedure to cleanup this module! (V33)
  5971. *
  5972. *   SYNOPSIS
  5973. *    _DateCleanup();
  5974. *
  5975. *    void _DateCleanup(void);
  5976. *
  5977. *   FUNCTION
  5978. *    Cleanup this module, after using!
  5979. *
  5980. *   INPUTS
  5981. *    None.
  5982. *
  5983. *   RESULT
  5984. *    None.
  5985. *
  5986. *   EXAMPLE
  5987. *    ...
  5988. *    _DateCleanup();
  5989. *    ...
  5990. *
  5991. *   NOTES
  5992. *    This function is only needed/available if you do not compile this
  5993. *    with a SAS C Compiler (using Autoinitialization!)
  5994. *    If you are not using SASC - don't forget to cleanup this module with
  5995. *    this function - or you will get into trouble!!!
  5996. *
  5997. *   BUGS
  5998. *    unknown.
  5999. *
  6000. *   SEE ALSO
  6001. *
  6002. *
  6003. *****************************************************************************
  6004. *
  6005. *
  6006. */
  6007.  
  6008.  {
  6009.   #ifdef _AMIGA
  6010.   if (locale != NULL)
  6011.     CloseLocale(locale);
  6012.     #ifndef __SASC_650
  6013.       if (LocaleBase != NULL)
  6014.         CloseLibrary(LocaleBase);
  6015.     #endif
  6016.   #endif
  6017.  }
  6018.